lib/keen/aes_helper.rb in keen-0.9.0 vs lib/keen/aes_helper.rb in keen-0.9.1
- old
+ new
@@ -5,15 +5,16 @@
module Keen
module AESHelper
BLOCK_SIZE = 32
- def aes256_encrypt(key, plaintext)
+ def aes256_encrypt(key, plaintext, iv = nil)
aes = OpenSSL::Cipher::AES.new(256, :CBC)
aes.encrypt
aes.key = key
- iv = aes.random_iv
+ aes.iv = iv unless iv.nil?
+ iv ||= aes.random_iv
[aes.update(plaintext) + aes.final, iv]
end
def aes256_decrypt(key, iv_plus_encrypted)
iv = iv_plus_encrypted[0, 16]
@@ -38,6 +39,6 @@
padding = pad_len.chr * pad_len
padded = msg + padding
padded
end
end
-end
\ No newline at end of file
+end