Class: Decrypt

Inherits:
Object
  • Object
show all
Defined in:
lib/encrypt_column/decrypt.rb

Class Method Summary collapse

Class Method Details

.cipher(ciphertext, key = ENV['ENCRYPTION_KEY']) ⇒ Object



2
3
4
5
6
7
8
# File 'lib/encrypt_column/decrypt.rb', line 2

def self.cipher(ciphertext, key = ENV['ENCRYPTION_KEY'])
  raise 'Encryption Key Config Missing' unless key.present?
  ActiveSupport::MessageEncryptor.new(key).decrypt_and_verify(ciphertext)
rescue ActiveSupport::MessageVerifier::InvalidSignature
  return 'ERROR: Missing encryption ciphertext' if ciphertext.nil? || ciphertext.blank?
  return 'ERROR: Wrong encryption key specified'
end