Forum Moderators: coopster

Message Too Old, No Replies

Warning: mcrypt ecb(): Attempt to use an empty IV, which is NOT recomm

Any one know a fix for this?

         

capulet_x

9:31 pm on Mar 27, 2007 (gmt 0)

10+ Year Member



Hello,

Would someone mind posting an example of how to properly use mcrypt_ecb?
This is the piece of my code I'm having trouble with below.
I've done quite a few searches but keep coming up empty on the proper syntax from start to finish.

$key = "unlock";

$msg = " top secret ";

$crypted = mcrypt_ecb(MCRYPT_LOKI97, $key, $msg, MCRYPT_ENCRYPT);

$crypted = bin2hex($crypted);

echo "$crypted";

eelixduppy

9:40 pm on Mar 27, 2007 (gmt 0)



Hello,

mcrypt ecb
is depreciated and shouldn't really be used. Instead, you should be using mcrypt_generic [php.net]. There's an example of its use on php.net here recopied below:

$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);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
echo $encrypted_data;

[us3.php.net...]

Good luck! :)

capulet_x

11:40 pm on Mar 27, 2007 (gmt 0)

10+ Year Member



Great it's encrypted!...but how do I diciper it? I didn't see a clear example on the link.

eelixduppy

11:47 pm on Mar 27, 2007 (gmt 0)



You have to use mdecrypt_generic [us2.php.net].

There's an example on that page :)

capulet_x

2:31 am on Mar 28, 2007 (gmt 0)

10+ Year Member



Thank you for the link!
It seems thought that my problem is more complicated than I thought. Apparently to decrypt I have to reinitialize the encryption buffer with mcrypt_generic_init() before decrypting the data. This is a problem as I have called for the value from my database using a form on a PREVIOUS PAGE, encrypted the result of that query, and created cookie of the encrypted value. My intent was to use the encrypted cookie on the following page as a variable.
My dilemma is in order to decipher the cookie so that my function performs correctly it looks like I have to define the terms of the initial encryption AGAIN....which means that I have to define the INITIAL value of the encrypted cookie...which means I have to call the query I just called on the previous page...which of course relied on the variables in the previous page's form.

(whew!)

No chance there is a way I can call on variables from a previous page is there?

or do I have to merge these two pages into one (Which I would really hate to do it was difficult enough getting them to work all by themselves)

I thought I could encrypt the data

$encrypteddata

and then use something like

echo "The secret password is:" .?encrypteddata = ©Âûr”q‘ûn¬.¢¿Î܇òAÉ\0

Should I just use base_64 encode?