require ‘openssl’
require ‘base64’
require ‘hex_string’
require ‘pry’
$data = [“suni”,“1”,“nagoore”,"@gmail.com"]
$enc = []
cipher = OpenSSL::Cipher::AES.new(128, :CBC)
cipher.encrypt
key = cipher.random_key
iv = cipher.random_iv
#start the encryption process
$data.each do |k|
encrypted = cipher.update(k) + cipher.final
$enc << encrypted
end
puts $enc
#start the decryptuion process
$enc.each do |j|
decipher = OpenSSL::Cipher::AES.new(128, :CBC)
decipher.decrypt
decipher.padding = 0
decipher.key = key
decipher.iv = iv
plain = decipher.update(j) + decipher.final
puts plain
end