如何为进程打开或使用的文件计算MD5哈希?
文件可以是txt或exe
这是我当前的代码
public static string GetMd5HashFromFile(string fileName) { FileStream file = new FileStream(fileName,FileMode.Open); MD5 md5 = new MD5CryptoServiceProvider(); byte[] retVal = md5.ComputeHash(file); file.Close(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < retVal.Length; i++) { sb.Append(retVal[i].ToString("x2")); } return sb.ToString(); }
干杯.