Difference in SHA1 in .NET and MySQL Difference in SHA1 in .NET and MySQL mysql mysql

Difference in SHA1 in .NET and MySQL


In the MySQL example you are encoding to a hexadecimal string, in the .NET example you are encoding in ASCII. The two encodings are not the same.

If you convert to hexadecimal in the .NET version you get the correct result:

string hex = BitConverter.ToString(hashedPasswordBytes);

Result:

5B-AA-61-E4-C9-B9-3F-3F-06-82-25-0B-6C-F8-33-1B-7E-E6-8F-D8


You need to put [?a??????%l?3~??? in HEX representation. What you are printing is probably in binary form (hence the multiple ? chars).

Try doing this:

string hexstring = BitConverter.ToString(hashedPasswordBytes);

And see if hexstring and MySQL hash match.


The following will give you an exact match to what MySQL produces:

 BitConverter.ToString(SHA1CryptoServiceProvider.Create().ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(Password))).Replace("-", "").ToLower();