Using mcrypt in PHP

From: Date: Mon, 20 Aug 2001 01:03:56 +0000
Subject: Using mcrypt in PHP
Groups: php.general 
Request: Send a blank email to php-general+get-63436@lists.php.net to get a copy of this message
There seems to be no reliable information in the manual about how to do this. I'm trying to use mcrypt 2.4 with php4.06, which should be a compatible combination. So far, I have gotten it to work like this: $cypher = MCRYPT_RIJNDAEL_128; $encrypted = mcrypt_encrypt($cypher, $key, $plaintext, MCRYPT_MODE_ECB); $decrypted = mcrypt_decrypt($cypher, $key, $encrypted, MCRYPT_MODE_ECB); However, when I do this, I get an error saying: Warning: attempt to use an empty IV, which is NOT recommend in So I tried to do the same thing with an IV: $iv = mcrypt_create_iv(mcrypt_get_iv_size($cypher, MCRYPT_MODE_ECB), MCRYPT_RANDOM); and then added this $iv as an argument to encrypt and decrypt. At this point, it doesn't work, because the iv is different in the encrypt and decrypt functions, because it is randonly generated. Is it true that I need the same iv to encrypt as to decrypt? I'm just not understanding how to use this. All I want to do is to encrypt stuff and then decrypt it, using a key, right? It used to work. Thanks.

« previous php.general (#63436) next »