<p>问题不是键的填充,而是你使用了两种不同的块大小。在PHP中,使用<code>MCRYPT_RIJNDAEL_256</code>使用的块大小为。。。256位。但是,在使用<code>Crypt::Rijndael</code>的perl中,他们注意到:</p>
<blockquote>
<p><strong>blocksize</strong><br/>
The blocksize for Rijndael is 16 bytes (128 bits), although the algorithm actually supports any blocksize that is any multiple of our bytes. <strong>128 bits, is however, the AES-specified block size, so this is all we support</strong>.</p>
</blockquote>
<p>所以没有密钥可以在不同的算法之间进行转换。您可以在PHP中切换到128位:</p>
<pre><code><?
$key = "abcdefghijklmnopqrstuvwxyz";
$data = "Meet me at 11 o'clock behind the monument.";
$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_ECB, nil);
echo bin2hex($crypttext) . "\n";
// prints c613d1804f52f535cb4740242270b1bcbf85151ce4c874848fd1fc2add06e0cc2d26b6403feef4a8df18f7dd7f8ac67d
?>
</code></pre>
<p>Perl可以使用Crypt::Rijndael解密而不出问题:</p>
^{pr2}$
<p>或者您可以切换到支持更多块大小的不同Perl模块,例如<a href="http://search.cpan.org/~delta/Crypt-Rijndael_PP-0.04/Rijndael_PP.pm">Crypt::Rijndael_PP</a>:</p>
<pre><code># Same PHP code except using MCRYPT_RIJNDAEL_256
# prints f38469ec9deaadbbf49bb25fd7fc8b76462ebfbcf149a667306c8d1c033232322ee5b83fa87d49e4e927437647dbf7193e6d734242d583157b492347a2b1514c
</code></pre>
<p>Perl语言:</p>
<pre><code>use Crypt::Rijndael_PP ':all';
$key = "abcdefghijklmnopqrstuvwxyz\0\0\0\0\0\0";
$crypttext = "f38469ec9deaadbbf49bb25fd7fc8b76462ebfbcf149a667306c8d1c033232322ee5b83fa87d49e4e927437647dbf7193e6d734242d583157b492347a2b1514c";
print rijndael_decrypt(unpack('H*', $key), MODE_ECB, pack('H*', $crypttext), 256, 256);
# prints "Meet me at 11 o'clock behind the monument."
</code></pre>