class EncryptedField::PolicyWithIV

EncryptedField::PolicyWithIV all the logic required to encrypt/decrypt data using symmetric encryption.

Constants

DEFAULT_SEPARATOR

Public Instance Methods

decrypt(encrypted_str) click to toggle source
# File lib/encrypted-field/policy_with_iv.rb, line 19
def decrypt(encrypted_str)
  iv, encrypted_str = encrypted_str.split(separator, 2)
  cipher = create_cipher.decrypt
  cipher.key = secret_key
  cipher.iv = decode_iv(iv)
  cipher.update(decode_payload(encrypted_str) << cipher.final)
end
encrypt(str) click to toggle source
# File lib/encrypted-field/policy_with_iv.rb, line 11
def encrypt(str)
  cipher = create_cipher.encrypt
  cipher.key = secret_key
  iv = cipher.random_iv
  encrypted_str = cipher.update(str) << cipher.final
  encode_iv(iv) << separator << encode_payload(encrypted_str)
end
separator() click to toggle source
# File lib/encrypted-field/policy_with_iv.rb, line 27
def separator
  options[:separator] || DEFAULT_SEPARATOR
end