C#获取文件MD5值方法
2016-06-14 16:28
274 查看
private 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 new Exception("GetMD5HashFromFile() fail,error:" + ex.Message); } }
相关文章推荐
- C#使用Monitor类、Lock和Mutex类进行多线程同步
- C#多线程学习(六) 互斥对象
- C#多线程学习(五) 多线程的自动管理(定时器)
- C#多线程学习(四) 多线程的自动管理(线程池)
- 使用C#格式化字符串
- C#多线程学习(三) 生产者和消费者
- C# 计算程序用时
- C# 7.0 新特性1之基于Tuple的“多”返回值方法
- C#中byte与short、int、long互相转化
- C# 异常类型
- C# 终止线程
- Windows服务 开机自动运行
- C#中显现串口通信SerialPort类
- C#Windows服务:一些方法(启动、停止等)
- C# 设置应用程序开机自动运行
- wpf中应该使用c#四种定时器中的DispatcherTimer
- C#图像处理技术资料目录
- 推荐一本好的c#高级程序设计教程
- C# BackgroundWorker 详解
- C#读写应用程序配置文件