简体   繁体   English

正在返回“System.Byte []”而不是实际数据

[英]“System.Byte[]” is being returned instead of the actual data

This code is intended to calculate and print the MD5 hash of a file on my desktop. 此代码用于计算和打印桌面上文件的MD5哈希值。 However, on compilation all that is written to the console window is "System.Byte[]" Putting a ToString() didn't resolve the issue either. 但是,在编译时,所有写入控制台窗口的是“System.Byte []”。放置ToString()也没有解决问题。

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: 您可以使用BitConverterbyte[]数组中创建十六进制字符串:

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. BitConverter.ToString()为您提供AA-AA-AA-AA形式的表示,因此您必须删除连字符并使字符串小写以获得公共MD5十六进制字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM