1. 首页
  2. 编程语言
  3. C#
  4. 获取文件MD5码

获取文件MD5码

上传者: 2018-12-25 02:10:14上传 EXE文件 9KB 热度 76次
用时没找到工具,自己写了个,函数如下: private 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 new Exception("GetMD5HashFromFile() fail,error:" + ex.Message); } }
用户评论