RE: [PHP] Re: Mcrypt functions
| From: | Jay Smith | Date: | Tue, 03 Jun 2003 20:10:56 +0000 |
| Subject: | RE: [PHP] Re: Mcrypt functions | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-150055@lists.php.net to get a copy of this message | ||
You're using the same input for both encryption and decryption. Change the
decryption line to
$decrypted = mcrypt_ecb(MCRYPT_BLOWFISH, $key, $encrypted, MCRYPT_DECRYPT,
$iv);
srand() isn't doing anything here, you can get rid of it. Also, the IV does
nothing here, it is ignored in ECB mode. Try using something like CBC mode.
J
Daniel Rychlik wrote:
> I read more on vector IV and I agree with you. I've been reading this
> manual on mcrypt_encrypt and _decrypt functions. I came up with this from
> what I read and pretty much took the example. I have a problem with my
> decrypt statement. Im passing what I believe is the correct params, but I
> could be mistaken.
>
> Output from my function...
>
> ?Ü_ V¢¢''?Ê'ÅÆû´3?ån2V½kôR¤üyÐw?í? y}P×?õe ` <- Encrypted
> Data...
> 8?Ì«¢R¿?Þ6¡4±eÚ]xàLoìm
> 2?*?
> ê«ï " ? ez;Tê_=G?<- Decrypted data...
>
> code <snipit>
>
> srand();
> $key = "this is a secret key";
> $input = "Let us meet at 9 o'clock at the secret place.";
>
> $size = mcrypt_get_iv_size (MCRYPT_BLOWFISH, MCRYPT_MODE_ECB);
>
> $iv = mcrypt_create_iv($size, MCRYPT_RAND);
>
>
> $encrypted = mcrypt_ecb (MCRYPT_BLOWFISH, $key, $input, MCRYPT_ENCRYPT,
> $iv);
>
> echo $encrypted," <- Encrypted Data...<br/>";
>
> $decrypted = mcrypt_ecb (MCRYPT_BLOWFISH, $key, $input, MCRYPT_DECRYPT,
> $iv);
>
> echo $decrypted, "<- Decrypted data...<br/>";
>