Class: SymmetricEncryption::Encoder::Base16

Inherits:
Object
  • Object
show all
Defined in:
lib/symmetric_encryption/encoder.rb

Instance Method Summary collapse

Instance Method Details

#decode(encoded_string) ⇒ Object



94
95
96
97
98
99
# File 'lib/symmetric_encryption/encoder.rb', line 94

def decode(encoded_string)
  return encoded_string if encoded_string.nil? || (encoded_string == "")

  decoded_string = [encoded_string].pack("H*")
  decoded_string.force_encoding(SymmetricEncryption::BINARY_ENCODING)
end

#encode(binary_string) ⇒ Object



87
88
89
90
91
92
# File 'lib/symmetric_encryption/encoder.rb', line 87

def encode(binary_string)
  return binary_string if binary_string.nil? || (binary_string == "")

  encoded_string = binary_string.to_s.unpack("H*").first
  encoded_string.force_encoding(SymmetricEncryption::UTF8_ENCODING)
end