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?n2VkRyw?? y}P?e ` <- Encrypted Data...
> 8?̫R?64e]xLom
> 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/>";
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to