码迷,mamicode.com
首页 > 编程语言 > 详细

ruby 实现java中的aes 加密解密

时间:2018-03-20 12:47:12      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:abc   log   code   lin   openssl   def   nbsp   open   encode   

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
 

ruby 实现java中的aes 加密解密

标签:abc   log   code   lin   openssl   def   nbsp   open   encode   

原文地址:https://www.cnblogs.com/tomtang/p/8608303.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!