module SimplyAES::Format::Base64

A Base64 implementation of SimplyAES::Format that emits strings without newlines and can handle concatenated-b64 strings

Public Instance Methods

dump(bytestring) click to toggle source
# File lib/simply-aes/format.rb, line 62
def dump(bytestring)
  ::Base64.encode64(bytestring).tr("\n", '')
end
load(formatted) click to toggle source
# File lib/simply-aes/format.rb, line 53
def load(formatted)
  # Because Base64 has 3:4 raw:formated ratio, it doesn't always break
  # cleanly on byte boundaries; add support for concatenated
  # iv+ciphertext encoded payloads
  formatted.scan(/[^=]+(?:=+|\Z)/m).map do |chunk|
    ::Base64.decode64(chunk)
  end.join
end