我希望能让事情更加清晰简单。如果我有1GB的内存,并且尝试计算一个2GB文件的MD5哈希值,该怎么办?目前,我的处理方式是:
private static string Md5Hash(byte[] input)
{
byte[] hash = MD5.Create().ComputeHash(input);
StringBuilder builder = new StringBuilder(32);
foreach(byte b in hash)
{ builder.Append(b.ToString("X2")); }
return builder.ToString();
}
// I'm using it like: 'Md5.AsString(File.ReadAllBytes(filePath))'
那么你有什么建议?
File.OpenRead
而不是File.ReadAllBytes
。 - Cheng Chen