Method: ActiveRecord::Encryption::Cipher#decrypt

Defined in:
activerecord/lib/active_record/encryption/cipher.rb

#decrypt(encrypted_message, key:) ⇒ Object

Decrypt the provided Message.

When key is an Array, it will try all the keys raising a ActiveRecord::Encryption::Errors::Decryption if none works.



25
26
27
28
29
# File 'activerecord/lib/active_record/encryption/cipher.rb', line 25

def decrypt(encrypted_message, key:)
  try_to_decrypt_with_each(encrypted_message, keys: Array(key)).tap do |decrypted_text|
    decrypted_text.force_encoding(encrypted_message.headers.encoding || DEFAULT_ENCODING)
  end
end