I'm trying to use ARCFOUR algorithm in my PHP code:
$td = mcrypt_module_open(MCRYPT_ARCFOUR, '', MCRYPT_MODE_CBC, '');
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
mcrypt_generic_init($td, $key, $iv);
$output = mcrypt_generic($td, $input);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
and the problem is that the first line returns warning:
mcrypt_module_open(): Could not open encryption module
My settings:
From php_info() output:
command configure: ... "--with-mcrypt=static" ...
If I'm correct it means I do not need a DLL for mcrypt extension.
Supported ciphers: cast-128 gost rijndael-128 twofish arcfour cast-256 loki97 rijndael-192 saferplus wake blowfish-compat des rijndael-256 serpent xtea blowfish enigma rc2 tripledes
PHP version 5.3.8
Wamp 2.2a (32 bits)
Thank you for help!
As of PHP 5.3.6 and 5.4.0 RC6, the
arcfour
,wake
andenigma
mcrypt ciphers require the use ofstream
mode. They will not initialize any of the other modes, nor can any of the other ciphers usestream
mode.This may be true of earlier PHP versions as well.
Demo code, with the
@
present to silence the "can't open module" warning:Demo output:
It looks like you (and I) are seeing PHP bug 49311, which was closed after no feedback in 2009. RC4, WAKE and Enigma are broken. Code to demonstrate the problem:
Output on my system, from the PHP interactive prompt:
Until (unless) they fix this bug or a workaround is found, you'll want to choose a different encryption algorithm.
These three are stream cyphers. All other cyphers are block cyphers. They can't use the same modes as each other.
So just use MCRYPT_MODE_STREAM where you are using MCRYPT_MODE_CBC and you should be golden.
If not, use something like this:
Works for me.