11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/encrypt_column/decrypt.rb', line 11
def self.ciphertext(ciphertext, key = ENV['ENCRYPT_KEY'])
raise 'Encryption Key Config Missing' unless key.present?
return 'ERROR: Missing encryption ciphertext' if ciphertext.nil? || ciphertext.blank?
enciphered, iv = ciphertext.split('--', 2).map { |part| part.unpack('m')[0] }
decipher = OpenSSL::Cipher::AES256.new(:CBC)
decipher.decrypt
decipher.key = key
decipher.iv = iv
deciphered = decipher.update(enciphered)
deciphered << decipher.final
end
|