Documentation for a Third-Party API that I'm working with states:
"[O]ur API only accepts padded Base64 encoded strings."
What are "padded Base64 encoded strings" and how can I generate them in Ruby. The code below is my first attempt at creating JSON formatted data converted to Base64.
xa = Base64.encode64(a.to_json)
The padding they are talking about is actually part of Base64 itself. It's the "=" and "==" at the end. Base64 encodes packets of 3 bytes into 4 encoded characters. So if your input data has length n and
No need for you to change your code.
It looks like the base64
library pads by default; padding in Base64 would be the =
characters on the end of the data.
You can see this by running the following in the irb console:
irb(main):002:0> require 'base64'
=> true
irb(main):003:0> Base64.encode64('a')
=> "YQ==\n"
Without the padding, you couldn't be sure whether YQ
was everything or whether it was missing something.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With