/// <summary> /// 获取文件的MD5码 /// </summary> /// <param name="filePath">文件路径</param> /// <returns>MD5码</returns> private static string GetFileMD5(string filePath) { try { var file = new FileStream(filePath, FileMode.Open); MD5 md5 = new MD5CryptoServiceProvider(); var retval = md5.ComputeHash(file); file.Close(); var stringBuilder = new StringBuilder(); foreach (var t in retval) { stringBuilder.Append(t.ToString("x2")); } return stringBuilder.ToString(); } catch (Exception) { return null; } }
原文地址:https://www.cnblogs.com/dxx8575/p/8287655.html
时间: 2024-12-08 10:34:56