Page 1 of 1

Unable to decrypt data encrypted by PHP in C#

Posted: Wed Aug 20, 2008 10:16 pm
by lindy
.NET cannot decrypt the data encrypted by PHP.
.NET and PHP share the same key. Does anyone have any idea?
Following is the implementation in PHP

Code: Select all

 
$data = '4111111111111111';
$key = '1im2rlueghqkke54gnoe0x0jwne966d7';
// Select an algorithm and encryption mode
$algorithm = MCRYPT_BLOWFISH;
$mode = MCRYPT_MODE_CBC;
// Create an initialization vector
$iv = mcrypt_create_iv(mcrypt_get_iv_size($algorithm,$mode),MCRYPT_RAND);
// Encrypt the data
$encrypted_data = mcrypt_encrypt($algorithm, $key, $data, $mode, $iv);
$encrypted_data = base64_encode($encrypted_data);
echo "******".$encrypted_data;
// Decrypt the data
$encrypted_data = base64_decode($encrypted_data);
$decrypted_data = mcrypt_decrypt($algorithm, $key, $encrypted_data, $mode, $iv);
print "The decoded data is $decrypted_data";
 

Re: Unable to decrypt data encrypted by PHP in C#

Posted: Thu Aug 21, 2008 12:44 am
by it2051229
C# != PHP.. encrypting mechanism of C# != encrypting mechanism of PHP.. even though they have the same key...

Re: Unable to decrypt data encrypted by PHP in C#

Posted: Thu Aug 21, 2008 12:07 pm
by lindy
Yes, .NET != PHP.
I would like to know how PHP or .NET can achieve to decrypt the data which is encrypted by using MCRYPT_BLOWFISH cipher and MCRYPT_MODE_CBC mode.

Re: Unable to decrypt data encrypted by PHP in C#

Posted: Fri Aug 22, 2008 12:19 am
by it2051229
you can create your own encrypting and decrypting mechanism where the two language can understand.. thats the simplest solution i can think of.