Possible Duplicate:
How to convert hex to a byte array?
I'm searching for a python compatible method in C# to convert hex to binary. I've reversed a hash in Python by doing this:
import sha
import base64
import binascii
hexvalue = "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8"
binaryval = binascii.unhexlify(hexvalue)
print base64.standard_b64encode(binaryval)
>> W6ph5Mm5Pz8GgiULbPgzG37mj9g=
So far all of the various Hex2Binary C# methods I've found end up throwing OverflowExceptions:
static string Hex2Binary(string hexvalue)
{
string binaryval = "";
long b = Convert.ToInt64(hexvalue, 16);
binaryval = Convert.ToString(b);
byte[] bytes = Encoding.UTF8.GetBytes(binaryval);
return Convert.ToBase64String(bytes);
}
Anybody got a tip on how to produce a C# method to match the python output?