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_decrypt()
    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

  

 
 
posted @ 2018-03-20 11:38  皓贤  阅读(269)  评论(0编辑  收藏  举报