Possible Duplicate:
How do you convert Byte Array to Hexadecimal String, and vice versa, in C#?
Convert hex string to byte array
I am encrypting a string in PHP and I would like to decrypt this string using C#. The last line of the encryption function will return a hexadecimal representation of the encrypted string. Unfortunately for me, though, I cannot figure out how to reverse this conversion through C#. I will post my source below:
PHP:
echo encrypt('hello'); // Returns '60eb44e27e73ba1d'
function encrypt($string) {
//Key
$key = "12345678";
//Encryption
$cipher_alg = MCRYPT_TRIPLEDES;
$iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher_alg,MCRYPT_MODE_ECB), MCRYPT_RAND);
$encrypted_string = mcrypt_encrypt($cipher_alg, $key, $string, MCRYPT_MODE_ECB, $iv);
return bin2hex($encrypted_string);
}
The only issue I am having is the hex2bin conversion in C# - the rest of the decryption function I have working. Feel free to ask for any further details.
Hopefully there is some simple solution out there that I don't know about. I appreciate any responses.
Regards,
Evan