Search code examples
phpencryptionmcrypt

PHP - stream_filter_append, unable to locate filter (mcrypt)


My config is (from 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 

So you see I have enabled mcrypt.

I try

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

and it's ok.

But when I try something like

stream_filter_append($fp, 'mcrypt.rijndael-256', STREAM_FILTER_WRITE, $opts);

I have two warnings

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

I guess it's wrong to write

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

but in this case I have only one warning

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

And the last thing. Encryption/description with "rot13" works well

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

So the question is how to encrypt/decrypt with some of the mcrypt methods?


Solution

  • I'm sorry I lost sight of some important details. One more string:

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

    And of course it fails because Rijndael-256 not supported in STREAM mode. So thank you for your comments and please sorry to trouble you.