PHP - stream_filter_append,无法定位过滤器(mcrypt)

时间:2015-02-17 07:57:00

标签: php encryption mcrypt

我的配置是(来自phpinfo()):

PHP Version 5.3.10
Registered Stream Filters: convert.iconv.*, mcrypt.*, mdecrypt.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk, zlib.*, bzip2.* 

mcrypt support: enable
mcrypt_filter support: enable
Version: 2.5.8
Supported ciphers: cast-128 gost rijndael-128 twofish cast-256 loki97 rijndael-192 saferplus wake blowfish-compat des rijndael-256 serpent xtea blowfish enigma rc2 tripledes arcfour
Supported modes: cbc cfb ctr ecb ncfb nofb ofb stream 

所以你看我启用了mcrypt。

我试试

mcrypt_module_open('rijndael-256', '', 'ofb', ''); 

没关系。

但是当我尝试像

这样的东西时
stream_filter_append($fp, 'mcrypt.rijndael-256', STREAM_FILTER_WRITE, $opts);

我有两个警告

stream_filter_append(): Could not open encryption module in ...
stream_filter_append(): unable to create or locate filter "mcrypt.rijndael-256" in ...

我认为编写

是错误的
stream_filter_append($fp, 'rijndael-256', STREAM_FILTER_WRITE, $opts); // without 'mcrypt.*'

但在这种情况下我只有一个警告

stream_filter_append(): unable to create or locate filter "rijndael-256" in ...

最后一件事。使用" rot13"进行加密/描述运作良好

stream_filter_append($fp, "string.rot13", STREAM_FILTER_WRITE);

所以问题是如何使用某些mcrypt方法加密/解密?

1 个答案:

答案 0 :(得分:0)

对不起,我忽略了一些重要的细节。 还有一个字符串:

$opts = array('iv' => $iv, 'key' => $key, 'mode' => 'stream');
stream_filter_append($fp, 'mcrypt.rijndael-256', STREAM_FILTER_WRITE, $opts);

当然它失败了,因为在STREAM模式下不支持Rijndael-256。 非常感谢您的评论,很抱歉给您带来麻烦。