【发布时间】:2011-05-06 22:09:03
【问题描述】:
我对这段代码有几个问题:
<?php
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$key = "This is a very secret key";
$text = file_get_contents('path/to/your/file');
echo strlen($text) . "\n";
$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv);
file_put_contents('path/to/your/file', $crypttext);
?>
它可以很好地加密文件,但是它在最后添加了额外的空值,所以如果我加密:
a test string is this one
and here is a new line
一旦解密就变成:
a test string is this one
and here is a new line 000000000000000
发生了什么事?
第二,MCRYPT_RIJNDAEL_256与AES-128兼容吗?
最后,我如何让另一方解密我加密的文件?他们需要知道使用了哪种加密,我不知道该告诉他们什么。
【问题讨论】:
-
我只能提供它使用 RIJNDAEL_256
-
如何将其更改为 AES 128?
标签: php encryption