C # MD5 Results hashes not expected result

I tried every example that I can find on the Internet, but I can not get my .NET code to create the same MD5 Hash results from my VB6 application.

The VB6 application gives identical results on this site: http://www.functions-online.com/md5.html

But I can't get the same results for the same input in C # (using the MD5.ComputeHash method or the FormsAuthentication encryption method)

Please, help!!!!

As requested, here is some kind of code. This is pulled straight from MSDN:

public string hashString(string input) { // Create a new instance of the MD5CryptoServiceProvider object. MD5 md5Hasher = MD5.Create(); // Convert the input string to a byte array and compute the hash. byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input)); // Create a new Stringbuilder to collect the bytes // and create a string. StringBuilder sBuilder = new StringBuilder(); // Loop through each byte of the hashed data // and format each one as a hexadecimal string. for (int i = 0; i < data.Length; i++) { sBuilder.Append(data[i].ToString("x2")); } // Return the hexadecimal string. return sBuilder.ToString(); } 

My test line:

QWERTY123TEST

Results of this code:

 8c31a947080131edeaf847eb7c6fcad5 

MD5 test result:

 f6ef5dc04609664c2875895d7da34eb9 

Note. TestMD5 Result Is What I Expect

Note. I really, really stupid, apologize - I just realized that I had the wrong input. As soon as I hardcoded it, it worked. thanks for the help

+4
source share
2 answers

This is the C # MD5 method that I know works, I used it for authentication through various web API remnants

  public static string GetMD5Hash(string input) { System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider(); byte[] bs = System.Text.Encoding.UTF8.GetBytes(input); bs = x.ComputeHash(bs); System.Text.StringBuilder s = new System.Text.StringBuilder(); foreach (byte b in bs) { s.Append(b.ToString("x2").ToLower()); } return s.ToString(); } 
+16
source

What makes the functions-online site ( http://www.functions-online.com/md5.html ) the authority of MD5? For me, it works fine only for ISO-8859-1. But when I try to insert anything other than ISO-8859-1 into it, it returns the same MD5 hash. Try using the Cyrillic alphabet B yourself, code 0x412. Or try the Chinese Chinese character for water, code 0x98A8. As far as I know, the published C # applet is correct.

+1
source

All Articles