Unable to decrypt data encrypted by PHP in C#

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
lindy
Forum Newbie
Posts: 2
Joined: Wed Aug 20, 2008 10:03 pm

Unable to decrypt data encrypted by PHP in C#

Post 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";
 
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

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

Post by it2051229 »

C# != PHP.. encrypting mechanism of C# != encrypting mechanism of PHP.. even though they have the same key...
lindy
Forum Newbie
Posts: 2
Joined: Wed Aug 20, 2008 10:03 pm

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

Post 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.
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

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

Post 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.
Post Reply