At http://pandorasdream.com/crypt2.php and http://pandorasdream.com/crypt.php I am having the same problems.
For each, I get a sometimes-works, sometimes fails result. The manual entry has a string of user notes with problem like mine, but I still have problems.
Here's the relevant PHPInfo stuff:
-->
PHP Version 4.1.2
Configure Command './configure' '--with-mysql' '--with-apache=../apache_1.3.23' '--enable-track-vars' '--with-xml' '--enable-
memory-limit=yes' '--enable-bcmath' '--with-gd=../gd-2.0.1' '--enable-gd-native-tt' '--enable-gd-imgstrttf' '--with-gdbm=/usr/include' '--enable-calendar' '--with-png-dir=/usr/lib' '--with-zlib-dir=/usr/include' '--with-freetype-dir=/usr/local/include/freetype2' '--with-jpeg-dir=/usr/local/lib' '--with-mcrypt' '--enable-trans-sid' '--with-sablot=/usr/local/lib' '--with-imap' '--enable-xslt' '--with-xslt-sablot' '--enable-sablot-errors-descriptive'
Server API Apache
mcrypt
mcrypt support enabled
version 2.4.x
Supported ciphers twofish rijndael-128 rijndael-192 rijndael-256
saferplus rc2 xtea serpent safer-sk64 safer-sk128 cast-256 loki97
gost threeway cast-128 des tripledes enigma arcfour panama wake
Supported modes ofb cfb nofb cbc ecb stream
--]
The first attempt used the following code:
-->
<?php
$key = "this is a secret key";
$input = "Let us meet at 9 o'clock at the secret place.";
$td = mcrypt_module_open ('tripledes', '', 'ecb', '');
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($td),
MCRYPT_RAND);
mcrypt_generic_init ($td, $key, $iv);
$encrypted_data = mcrypt_generic ($td, $input);
$decrypted_data = mdecrypt_generic ($td, $encrypted_data);
mcrypt_generic_end ($td);
echo "key:
$key<br>input:$input<br>encrypted:$encrypted_data<br>decrypted:$decryp
ted_data";
?>
--]
This resulted, at first, in "key: this is a secret key
input:Let us meet at 9 o'clock at the secret place.
encrypted:\ºþê™Ï'áž(v¹FýaõFËU³æç SäÇÚÖzßù5Qì<±_™-:Í
decrypted:Let us meet at 9 o'clock at the secret place."
BUT after I refreshed/reloaded a couple of times, I got
this: "Warning: mcrypt_generic_init: Memory allocation error
in /home/pndrdrm001/www/crypt.php on line 64
Warning: 1 is not a valid MCrypt resource
in /home/pndrdrm001/www/crypt.php on line 65
Warning: 1 is not a valid MCrypt resource
in /home/pndrdrm001/www/crypt.php on line 66
Warning: 1 is not a valid MCrypt resource
in /home/pndrdrm001/www/crypt.php on line 67
key: this is a secret key
input:Let us meet at 9 o'clock at the secret place.
encrypted:
decrypted: "
There were no changes to the code.
The second try used the following:
In file 1, the functions:
-->
<?php
function my_encrypt($sString)
{
GLOBAL $sCryptoKey;
$iIV = mcrypt_create_iv (mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256,
MCRYPT_MODE_EC😎, MCRYPT_RAND);
$sEncrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $sCryptoKey,
$sString, MCRYPT_MODE_ECB, $iIV);
return($sEncrypted);
} // End function my_encrypt
function my_decrypt($sString)
{
GLOBAL $sCryptoKey;
$iIV = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256,
MCRYPT_MODE_EC😎, MCRYPT_RAND);
$sDecrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $sCryptoKey,
$sString, MCRYPT_MODE_ECB, $iIV);
return(trim($sDecrypted));
} // End function my_decrypt
?>
--]
and in file 2, the main page:
-->
<?php
include "cryption.php";
$sCryptoKey = "key";
$input = "test";
$encrypted = my_encrypt($input);
$decrypted = my_decrypt($encrypted);
echo "key:
$sCryptoKey<br>input:$input<br>encrypted:$encrypted<br>decrypted:$decr
ypted";
?>
--]
This resulted in "key: key
input:test
encrypted: &foUÝø§ª~RM¡°Kz à¼O¼¿rw"x@nÉ
decrypted:test " the first time, but then I got "Fatal error:
generic_init failed
in /home/pndrdrm001/www/cryption.php on line 9" on the
second refresh.
Is there a missing call to free resources, or something? What can be
done?
Thanks!