Method: SymmetricEncryption.header

Defined in:
lib/symmetric_encryption/symmetric_encryption.rb

.header(encrypted_and_encoded_string) ⇒ Object

Returns the header for the encrypted string Returns [nil] if no header is present



165
166
167
168
169
170
171
172
173
174
# File 'lib/symmetric_encryption/symmetric_encryption.rb', line 165

def self.header(encrypted_and_encoded_string)
  return if encrypted_and_encoded_string.nil? || (encrypted_and_encoded_string == "")

  # Decode before decrypting supplied string
  decoded = cipher.encoder.decode(encrypted_and_encoded_string.to_s)
  return if decoded.nil? || decoded.empty?

  h = Header.new
  h.parse(decoded).zero? ? nil : h
end