What complements Base64 encoded strings and how can I generate them in ruby?

Documentation for a third-party API I'm working with states with:

"[O] ur API allows only filled Base64 encoded strings."

What are Base64 encoded filled strings and how can I generate them in Ruby. The code below is my first attempt at creating formatted JSON data converted to Base64.

  xa = Base64.encode64(a.to_json)
+5
source share
2 answers

The gasket they are talking about is actually part of Base64 itself. This is "=" and "==" at the end. Base64 encodes packets of 3 bytes into 4 encoded characters. Therefore, if your input is n and

  • n% 3 = 1 = > "=="
  • n% 3 = 2 = > "="

.

+5

base64; padding Base64 = .

, irb :

irb(main):002:0> require 'base64'
=> true
irb(main):003:0> Base64.encode64('a')
=> "YQ==\n"

, , YQ - - .

+2

All Articles