How to make Ruby AES-256-CBC and PHP MCRYPT_RIJNDAEL_128 play well together

前端 未结 4 672
梦如初夏
梦如初夏 2020-12-05 16:17

I\'m generating data to send from a Ruby stack to a PHP stack. I\'m using the OpenSSL::Cipher library on the Ruby side and the \'mcrypt\' library in PHP. When I encrypt us

4条回答
  •  鱼传尺愫
    2020-12-05 16:45

    I don't know PHP, but reading through related questions on the sidebar, I see Converting Ruby AES256 decrypt function to PHP. This includes a reference to this page, pointing out that the 128 in MCRYPT_RIJNDAEL_128 refers to the block size of the encryption, not the key size. You'll notice that the key size that you've passed between ruby and PHP is 256 bits in both cases. In other words, this seems to be the expected behavior, and you are using the larger key already.

    #!/usr/bin/ruby
    require 'base64'
    
    puts((Base64.decode64("RIvFgoi9xZaHS/0Bp0J9WDRyND6Z7jrd3btiAfcQ8Y0=").length * 8).to_s)
    

    HTH

提交回复
热议问题