i have the following example Code for using mcrypt with php:
/* Open the cipher */
$td = mcrypt_module_open('tripledes', '', 'ofb', '');
/* Create the IV and determine the keysize length, use MCRYPT_RAND
* on Windows instead */
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_DEV_RANDOM);
$ks = mcrypt_enc_get_key_size($td);
/* Create key */
$key = substr(md5('this is a very good key'), 0, $ks);
/* Intialize encryption */
mcrypt_generic_init($td, $key, $iv);
/* Encrypt data */
$encrypted = mcrypt_generic($td, 'This is very important data');
/* Terminate encryption handler */
mcrypt_generic_deinit($td);
/* Initialize encryption module for decryption */
mcrypt_generic_init($td, $key, $iv);
/* Decrypt encrypted string */
$decrypted = mdecrypt_generic($td, $encrypted);
/* Terminate decryption handle and close module */
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
/* Show string */
echo trim($decrypted) . "
<br>";
This code is working fine, but I have to use "enigma" instead of tripledes.
If I'm changing the first line to:
mcrypt_module_open('enigma', '', 'ofb', '');
I get the following errors:
Warning: mcrypt_module_open(): Could not open encryption module in /Applications/MAMP/htdocs/test/mcrypt.php on line 13
Warning: mcrypt_enc_get_iv_size() expects parameter 1 to be resource, boolean given in /Applications/MAMP/htdocs/test/mcrypt.php on line 17
Warning: mcrypt_create_iv(): Cannot create an IV with a size of less than 1 or greater than 2147483647 in /Applications/MAMP/htdocs/test/mcrypt.php on line 17
Warning: mcrypt_enc_get_key_size() expects parameter 1 to be resource, boolean given in /Applications/MAMP/htdocs/test/mcrypt.php on line 18
Warning: mcrypt_generic_init() expects parameter 1 to be resource, boolean given in /Applications/MAMP/htdocs/test/mcrypt.php on line 24
Warning: mcrypt_generic() expects parameter 1 to be resource, boolean given in /Applications/MAMP/htdocs/test/mcrypt.php on line 27
Warning: mcrypt_generic_deinit() expects parameter 1 to be resource, boolean given in /Applications/MAMP/htdocs/test/mcrypt.php on line 30
Warning: mcrypt_generic_init() expects parameter 1 to be resource, boolean given in /Applications/MAMP/htdocs/test/mcrypt.php on line 33
Warning: mdecrypt_generic() expects parameter 1 to be resource, boolean given in /Applications/MAMP/htdocs/test/mcrypt.php on line 36
Warning: mcrypt_generic_deinit() expects parameter 1 to be resource, boolean given in /Applications/MAMP/htdocs/test/mcrypt.php on line 39
Warning: mcrypt_module_close() expects parameter 1 to be resource, boolean given in /Applications/MAMP/htdocs/test/mcrypt.php on line 40
I don't know why this happens and how to fix it. If I'm checking the available modes with:
$modes = mcrypt_list_modes();
foreach ($modes as $mode) {
echo "$mode <br />
";
}
I get the following:
cbc
cfb
ctr
ecb
ncfb
nofb
ofb
stream
By checking the available algorithms:
$algorithms = mcrypt_list_algorithms("/usr/local/lib/libmcrypt");
foreach ($algorithms as $cipher) {
echo "$cipher<br />
";
}
I receive this output:
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
I hope someone knows what's the problem and how to fix this. Thanks!