Hello, I am getting some odd errors trying to get an encrypt/decrypt process to work. Looking at the manual examples and some other literature, I have tried the two approaches listed below. 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.
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:$decrypted_da ta"; ?> --] This resulted, at first, in "key: this is a secret key input:Let us meet at 9 o'clock at the secret place. encrypted:\ºþêTÏ'áz(v¹FýaõFËU³æç SäÇÚÖzßù5Qì<±_T-:Í 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/administrator/crypt.php on line 64 Warning: 1 is not a valid MCrypt resource in /home/pndrdrm001/www/administrator/crypt.php on line 65 Warning: 1 is not a valid MCrypt resource in /home/pndrdrm001/www/administrator/crypt.php on line 66 Warning: 1 is not a valid MCrypt resource in /home/pndrdrm001/www/administrator/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_ECB), 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_ECB), 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:$decrypted" ; ?> --] 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/administrator/cryption.php on line 9" on the second refresh. Is there a missing call to free resources, or something? What can be done? Thanks! Regards, Puru