Yes they are both defined - I did the echo for both and they displayed
on the web page.
I was wondering if maybe that iv parameter is the problem? does it
generate one data when I encrypt it and then another when I decrypt
it? The reason I wonder is that I can encrypt and decrypt
successfully if I do it in the same php script but if I encrypt only,
save the encryption string to disk and then use another php script to
open the file and decrypt it, it doesn't decrypt, it stays
scrambled???
If you run this you'll see that it works to encrypt and decrypt but if
I try to use just the part to encrypt and put the parts to decrypt
only in another script it won't decrypt:
/* Open the cipher */
// $td = mcrypt_module_open ('rijndael-256', '', 'ofb', '');
$td = mcrypt_module_open ('rijndael-256', '', 'ecb', '');
/* Create the IV and determine the keysize length */
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td),
MCRYPT_DEV_RANDOM);
$ks = mcrypt_enc_get_key_size ($td);
/* Create key */
$key = "follow the yellow brick road";
/* Intialize encryption */
mcrypt_generic_init ($td, $key, $iv);
/* Encrypt data */
$encrypted = mcrypt_generic ($td, 'secret 2 password');
/* 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 */
print trim ($decrypted)."\n";
$handle = fopen("/home/rfresh/public_html/ssfiles/mysqlpw.enc","w");
fputs($handle, $encrypted. "\n");
fclose($handle);
On Fri, 01 Aug 2003 10:37:08 +0200, stephan beal
<st*****@wanderinghorse.net> wrote:
Ralph Freshour wrote: $cipher_alg = MCRYPT_RIJNDAEL_128;
Are you 100% that MCRYPT_RIJNDAEL_128 is defined for your system? Try:
echo MCRYPT_RIJNDAEL_128;
// Create the initialization vector for added security.
$iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher_alg,
MCRYPT_MODE_ECB), MCRYPT_RAND);
Same for MCRYPT_MODE_ECB.
i ask because certain constants are only defined is specific libs are linked
in or if PHP was configured with them.