Ruby on Rails Decryption

前端 未结 2 1608
南笙
南笙 2021-01-26 04:36

The following function works perfect in PHP. How can it be translated in Ruby on Rails.

Please note that both privateKey and iv are 32 characters long.

m         


        
2条回答
  •  忘掉有多难
    2021-01-26 05:08

    Here some code which works for me :

    
    def decrypt_data(data, pwd, iv)
        encrypted_data = Base64.decode64(data)
        aes = OpenSSL::Cipher::Cipher.new("AES-256-CBC")
        aes.decrypt
        aes.key = Digest::MD5.hexdigest(pwd)
        aes.iv = iv
        result = aes.update(encrypted_data) + aes.final 
    end
    

    In my example the password is encrypted with MD5.

    I hope this help

提交回复
热议问题