Here are two hash generators:
Now, my question is:
Why do the hashes differ when trying to hash the char ‘€’ (0x80)?
I assume it happens because ‘€’ is not a normal ASCII character.
Which of the two hashes is ‘correct’?
I’m trying to calculate the hash returned by hash generator 1 with C#.
This hashing function doesn’t return it.
private string GetMD5Hash(string TextToHash)
{
if ((TextToHash == null) || (TextToHash.Length == 0))
{
return string.Empty;
}
MD5 md5 = new MD5CryptoServiceProvider();
byte[] textToHash = Encoding.Default.GetBytes(TextToHash);
byte[] result = md5.ComputeHash(textToHash);
return BitConverter.ToString(result).Replace("-", "").ToLower();
}
How could I change it so it returns the hash I want?
Additional Info:
I made a little AutoIt script:
#include <Crypt.au3>
ConsoleWrite(StringLower(StringMid(_Crypt_HashData(Chr(128), $CALG_MD5),3)) & @CRLF)
and it returns the hash I want!
However I need a C# code 🙂
It comes down to which encoding you use to turn the
stringinto abyte[](hence my suggestion to use try UTF-8, as that is a pretty common choice here; however, any full unicode encoding would work as long as you know which to use) ; for example, based on the string"abc€"we can deduce that the first site might be using any of:Personally, I’d use UTF-8!
Here’s the code I used to find the candidate encodings:
Further, testing with the string
"dnos ʇǝqɐɥdʃɐ"shows that the second site is definitely using UTF-8; the first site finds no matches, so I guess it is using a code-page based encoding, and in short will not work reliably with the full range of unicode.