toplay wrote:If phpinfo() says that mcrypt is enabled, then things should be fine. Perhaps you just misspelled the function name.
Please post the exact code in question and what error(s) you're getting.
🙂
Ok, here's something interesting. I just tried every mcrypt function in the manual and while most don't work, returning "Call to undefined function", a few do work.
They are:
- mcrypt_cbc()
- mcrypt_cfb()
- mcrypt_create_iv();
- mcrypt_ecb();
- mcrypt_get_block_size()
- mcrypt_get_cipher_name()
- mcrypt_get_iv_size()
- mcrypt_get_key_size()
- mcrypt_ofb();
To say they work is a bit of a stretch as i haven't actually tested them, but using them without any parameters I get "wrong parameter count" which at least means they're recoginized.
Also, when viewing the results of phpinfo(), there's only one line below the mcrypt section and that is "version 2.2.x" there's a table immediately below it for "Directive / Local Value / Master Value" but there's nothing in it. Should there be?
The source code i was originally using was to test the module installation and determine which encryption methods and algorithms i had to work with.
Here's that code:
if (!extension_loaded('mcrypt')) {
print "mcrypt not loaded!";
exit;
}
function mcrypt_check_sanity() {
$modes = mcrypt_list_modes();
$algorithms = mcrypt_list_algorithms();
foreach ($algorithms as $cipher) {
if(mcrypt_module_self_test($cipher)) {
print $cipher." ok.\n";
} else {
print $cipher." not ok.\n";
}
foreach ($modes as $mode) {
if(mcrypt_test_module_mode($cipher,$mode)) {
$result = "ok";
} else {
$result = "not ok";
}
print $cipher." in mode ".$mode." ".$result."\n";
mcrypt_module_close($td);
}
}
}
function mcrypt_test_module_mode($module,$mode) {
/* Data */
$key = 'this is a very long key, even too long for the cipher';
$plain_text = 'very important data';
/* Open module, and create IV */
$td = mcrypt_module_open($module, '',$mode, '');
$key = substr($key, 0, mcrypt_enc_get_key_size($td));
$iv_size = mcrypt_enc_get_iv_size($td);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
/* Initialize encryption handle */
if (mcrypt_generic_init($td, $key, $iv) != -1) {
/* Encrypt data */
$c_t = mcrypt_generic($td, $plain_text);
mcrypt_generic_end($td);
mcrypt_module_close($td);
/* Reinitialize buffers for decryption */
/* Open module, and create IV */
$td = mcrypt_module_open($module, '', $mode, '');
$key = substr($key, 0, mcrypt_enc_get_key_size($td));
$iv_size = mcrypt_enc_get_iv_size($td);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
mcrypt_generic_init($td, $key, $iv);
$p_t = mdecrypt_generic($td, $c_t);
/* Clean up */
mcrypt_generic_end($td);
mcrypt_module_close($td);
}
if (strncmp($p_t, $plain_text, strlen($plain_text)) == 0) {
return TRUE;
} else {
return FALSE;
}
}
mcrypt_check_sanity();
I get the following error:
Fatal error: Call to undefined function: mcrypt_list_modes()