此代码旨在计算并打印桌面上文件的 MD5 哈希值。但是,在编译时,写入控制台窗口的所有内容都是“System.Byte[]”,放置 ToString() 也没有解决问题。
MD5 a = MD5.Create();
Console.Write(a.ComputeHash(File.OpenRead(@"C:\Users\TTDDWW\Desktop\putty.exe")));
Console.ReadKey();
您可以使用BitConverter
创建一个十六进制字符串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()
为您提供表格的表示AA-AA-AA-AA
因此,您必须删除连字符并将字符串变为小写才能获得常见的 MD5 十六进制字符串。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)