【发布时间】:2015-10-22 00:32:03
【问题描述】:
我在使用加密过滤器http://php.net/manual/en/filters.encryption.php时遇到了一些问题
该代码适用于三重算法,但是,当更改为 rijndael-256 或 128 时,它只会在读取时产生乱码。
我认为这是 IV 或密钥系统的错误,所以我尝试在读写中使用硬编码对,但是它仍然会产生乱码。
public function writeEncrypt($path, $data){
$key = "1234567812345678";
$iv = "1234567812345678";
$opts = array('iv'=>$iv, 'key'=>$key, 'mode'=>'cbc');
$fp = fopen($path, 'wb');
stream_filter_append($fp, 'mcrypt.rijndael-128', STREAM_FILTER_WRITE, $opts);
fwrite($fp, $data);
fclose($fp);
return true;
}
public function readDecrypt($path){
$key = "1234567812345678";
$iv = "1234567812345678";
$opts = array('iv'=>$iv, 'key'=>$key, 'mode'=>'cbc');
$fp = fopen($path, 'rb');
stream_filter_append($fp, 'mcrypt.rijndael-128', STREAM_FILTER_READ, $opts);
$data = rtrim(stream_get_contents($fp));
fclose($fp);
header("Content-Type: application/zip");
header("Content-Length: " . count($data));
echo $data;
}
所有数据都以二进制形式输入。 我究竟做错了什么? (php日志中没有错误)
【问题讨论】:
标签: php encryption stream mcrypt rijndael