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_o pen ('rijndael-256', '', 'ofb', '');
$td = mcrypt_module_o pen ('rijndael-256', '', 'ecb', '');
/* Create the IV and determine the keysize length */
$iv = mcrypt_create_i v (mcrypt_enc_get _iv_size($td),
MCRYPT_DEV_RAND OM);
$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_generi c ($td, $encrypted);
/* Terminate decryption handle and close module */
mcrypt_generic_ deinit ($td);
mcrypt_module_c lose ($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*****@wander inghorse.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_i v(mcrypt_get_iv _size($cipher_a lg,
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.