Im working on converting an encryption library written in PHP over to C#, and have a small problem. When converting a HEX string to a string in PHP, and im getting a different value then my C# code which is supposed to be doing the exact same thing.
Here is the php code im using:
public function hex2str($hex)
{
$str = '';
for($i=0; $i<strlen($hex); $i+=2)
{
$str.=chr(hexdec(substr($hex, $i, 2)));
}
return $str;
}
And my C# code:
public static string Hex2Str(string hexString)
{
char[] mychar = new char[hexString.Length / 2];
for (var i = 0; i < mychar.Length; i++)
{
// Convert the number expressed in base-16 to an integer.
int value = Convert.ToInt32(hexString.Substring(i * 2, 2), 16);
string stringValue = Char.ConvertFromUtf32(value);
mychar[i] = (char)value;
}
return new String(mychar);
}
The Hex value im using is:
E0D644FCDEB4CCA04D51F617D59084D8
And here is a picture of the difference between the PHP script and my C# scripts return value:
If anyone can help me spot my mistake in the C# code, i would greatly appreciate your help!