-2

This is my code:

private static string ComputeMD5Hash(string input)
{
    using (MD5 md5 = MD5.Create())
    {
        byte[] inputBytes = Encoding.Default.GetBytes(input);
        byte[] hashBytes = md5.ComputeHash(inputBytes);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < hashBytes.Length; i++)
        {
            sb.Append(hashBytes[i].ToString("x2"));
        }
        return sb.ToString();
    }
}

The result MD5 from my code is: "91c8798099fac8762bb0e014084a3f08".

The result MD5 from online tool is: "8bb25958e7b1caad4a3be362d6098d76".

So, what the problem here? Why I can't get the same result I use .NET 5.

Mohammad
  • 11
  • 1

1 Answers1

0

I checked your code and it produced correct hash (on my machine). I used tool CyberChef to verify it.

The only problematic part could be the encoding. You have set Default. But try to specify UTF8 instead.

Kebechet
  • 1,461
  • 15
  • 31