class Encrypt
Public Class Methods
plaintext(plaintext, key = ENV['ENCRYPT_KEY'])
click to toggle source
# File lib/encrypt_column/encrypt.rb, line 9 def self.plaintext(plaintext, key = ENV['ENCRYPT_KEY']) return raise 'Missing Encryption Key Config' if key.nil? cipher = OpenSSL::Cipher::AES256.new(:CBC) iv = cipher.random_iv cipher.encrypt cipher.key = key cipher.iv = iv enciphered = cipher.update(plaintext) enciphered << cipher.final [enciphered, iv].map { |part| [part].pack('m').gsub(/\n/, '') }.join('--') end
text(plaintext, key = ENV['ENCRYPTION_KEY'])
click to toggle source
# File lib/encrypt_column/encrypt.rb, line 4 def self.text(plaintext, key = ENV['ENCRYPTION_KEY']) return raise 'Missing Encryption Key Config' if key.nil? ActiveSupport::MessageEncryptor.new(key).encrypt_and_sign(plaintext) end