ruby 实现java中的aes 加密解密

def aes_encrypt()

   cipher = OpenSSL::Cipher::AES.new(128, :CBC)

  cipher.encrypt cipher.key = "quck7295abvdefgh"
   data= 'sssssdsadkjak'
  cipher.iv = "abcdefghhigk"
  encrypted = cipher.update(data) + cipher.final Base64.strict_encode64(encrypted)
end
 
 
def  aes_dicrypt()

data = 'hWmnsBO1buB1=='
cipher = OpenSSL::Cipher.new('aes-128-cbc')
cipher.key = "quck7295abvdefgh"
cipher.iv = "abcdefghhigk"
cipher.decrypt
plain_text = ""
plain_text << cipher.update(Base64.decode64(data))
plain_text << cipher.final
return plain_text

end
 

转载于:https://www.cnblogs.com/tomtang/p/8608303.html

你可能感兴趣的:(ruby 实现java中的aes 加密解密)