This code is intended to calculate and print the MD5 hash of a file on my desktop. However, on compilation all that is written to the console window is "System.Byte[]" Putting a ToString() didn't resolve the issue either.
MD5 a = MD5.Create();
Console.Write(a.ComputeHash(File.OpenRead(@"C:\Users\TTDDWW\Desktop\putty.exe")));
Console.ReadKey();
You can use BitConverter
to create a hex string out of the byte[]
array:
MD5 a = MD5.Create();
byte[] hash = a.ComputeHash(File.OpenRead(@"C:\Users\TTDDWW\Desktop\putty.exe"));
string hexString = BitConverter.ToString(hash).Replace("-", string.Empty).ToLower();
Console.Write(hexString);
BitConverter.ToString()
gives you a representation of the form AA-AA-AA-AA
so you have to remove the hyphens and make the string lowercase to get the common MD5 hex string.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.