I'd like to use Ruby to decrypt a string that's encrypted with PHP. The same decryption logic works fine with PHP, but the Ruby code returns garbage.
The working PHP example:
<?php
$_RIJNDAEL_KEY_ = "uUxJIpSKMbOQQdtm6Y4rPEXeE9TAKUns";
$_RIJNDAEL_IV_ = "PiToVoRjwlg8UwxUxQKI4w==";
$ciphertext = 'T353/s48iKzAf61b2dCOnqUApYa4xxjye8he4oAtJHyyCKl8sCbI33hfP6IqOsQZEIWeQBCsvy97xwJMPD8RwLG4J0wgX9Ihlti1vMar+5nrLrCR4lAfZcoJopoBt1JVnDAojLW+y0S0y5c4GCdB8YrHzj4jv70dg3yX8DxlAWE=';
$content = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $_RIJNDAEL_KEY_, base64_decode($ciphertext), MCRYPT_MODE_ECB, $_RIJNDAEL_IV_);
echo $content . "\n";
?>
The not-working Ruby example:
require "openssl"
require "digest"
require "uri"
require "base64"
data = Base64.decode64("T353/s48iKzAf61b2dCOnqUApYa4xxjye8he4oAtJHyyCKl8sCbI33hfP6IqOsQZEIWeQBCsvy97xwJMPD8RwLG4J0wgX9Ihlti1vMar+5nrLrCR4lAfZcoJopoBt1JVnDAojLW+y0S0y5c4GCdB8YrHzj4jv70dg3yX8DxlAWE=")
key = Base64.decode64('uUxJIpSKMbOQQdtm6Y4rPEXeE9TAKUns')
iv = Base64.decode64('PiToVoRjwlg8UwxUxQKI4w==')
aes = OpenSSL::Cipher.new('AES-128-ECB')
aes.decrypt
aes.padding = 0
aes.key = key
aes.iv = iv
plain = aes.update(data) + aes.final
puts plain
Could anyone shed some light ? Thanks.