On 8/17/07, Sean <[EMAIL PROTECTED]> wrote:
> I am having issues with encryption/decryption.
>
> I am attempting to encrypt an integer (61663)
>
> when i decrypt it I get the following appended to my decrypted value.
>
> 61663\357\277\275\357\277\275\357\277\275
>
> $td = mcrypt_module_open('blowfish', '', 'cbc, '');
> $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
> mcrypt_generic_init($td, $key, $iv);
> $decrypted_data = mdecrypt_generic($td, base64_decode($input));
>
>
> BTW I base 64 encode the encypted integer(61663) and store it in a cookie
>
> Any Help would be greatly appreciated
>
> Thanks,
>
> Sean
>
I can see two potential problems:
You need to use the same initialization vector (IV) to decrypt as you
did to encrypt. Typically, after encryption, you prepend the iv to the
ciphertext value and store the whole thing (iv+encrypted). When you're
ready to decrypt, you chop the iv off the front and use it to decrypt
the ciphertext.
Second, how are you generating the key? Is it a multiple of 32 characters long?
--
Chris Snyder
http://chxo.com/
_______________________________________________
New York PHP Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk
NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com
Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php