Method: Krypton::AESCrypt.encrypt_data

Defined in:
lib/core/aes.rb

.encrypt_data(data, key, iv, cipher_type) ⇒ Object

Encrypts a block of data given an encryption key and an initialization vector (iv). Keys, iv’s, and the data returned are all binary strings. Cipher_type should be “AES-256-CBC”, “AES-256-ECB”, or any of the cipher types supported by OpenSSL. Pass nil for the iv if the encryption type doesn’t use iv’s (like ECB). :return: => String :arg: data => String :arg: key => String :arg: iv => String :arg: cipher_type => String



55
56
57
58
59
60
61
# File 'lib/core/aes.rb', line 55

def self.encrypt_data(data, key, iv, cipher_type)
  aes = OpenSSL::Cipher.new(cipher_type)
  aes.encrypt
  aes.key = key
  aes.iv = iv if iv != nil
  aes.update(data) + aes.final
end