标签:
/// <summary> /// 计算文件的MD5校验 /// </summary> /// <param name="fileName"></param> /// <returns></returns> public static string GetMd5HashFromFile(string fileName) { try { FileStream file = new FileStream(fileName, FileMode.Open); System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.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(); } catch (Exception ex) { throw; } }
经验证是正确的,可以和其他软件计算出来的MD5值对照。
标签:
原文地址:http://www.cnblogs.com/pengzhong/p/CsharpMd5.html