惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
B
Blog RSS Feed
Microsoft Security Blog
Microsoft Security Blog
Y
Y Combinator Blog
N
Netflix TechBlog - Medium
M
MIT News - Artificial intelligence
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
C
Check Point Blog
The GitHub Blog
The GitHub Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
P
Proofpoint News Feed
Martin Fowler
Martin Fowler
大猫的无限游戏
大猫的无限游戏
GbyAI
GbyAI
博客园_首页
A
About on SuperTechFans
Blog — PlanetScale
Blog — PlanetScale
人人都是产品经理
人人都是产品经理
T
Tailwind CSS Blog
aimingoo的专栏
aimingoo的专栏
T
The Blog of Author Tim Ferriss
The Cloudflare Blog

博客园 - Ants

我用 AI 辅助开发了一系列小工具(2):图片压缩工具 我用 AI 辅助开发了一系列小工具(1):文件提取工具 Spring Cloud中,Eureka常见问题总结 部署Spring Boot应用 C# FTP 命令无法获取ServerU目录列表问题 redis参数优化 memcached在windows下多实例并存 开源一个windows下的定时任务框架,简单粗暴好用。 WebRequest 访问 https Python定时任务框架APScheduler 3.0.3 Cron示例 Eclipse安装python注意事项 C# 为私有方法添加单元测试(反射) .net 操作sftp服务器 在ASP.NET MVC中使用Unity进行依赖注入的三种方式 ASP.NET Web API 安全筛选器 Token Based Authentication in Web API 2 IIS中查看W3P.exe进程对应的应用程序池的方法 WCF自定义Header sqlserver 用 RowNumber 分组
C# 计算文件MD5
Ants · 2015-04-30 · via 博客园 - Ants

因工作需要对文件进行是否被修改判断,整理的一段生成文件MD5码的代码:

   1:  public class FileHelper
   2:      {
   3:          /// <summary>
   4:          /// 对文件流进行MD5加密
   5:          /// </summary>
   6:          public static string MD5Stream(Stream stream)
   7:          {
   8:              MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
   9:              md5.ComputeHash(stream); 
  10:              byte[] b = md5.Hash;
  11:              md5.Clear();
  12:              StringBuilder sb = new StringBuilder(32);
  13:              for (int i = 0; i < b.Length; i++)
  14:              {
  15:                  sb.Append(b[i].ToString("X2"));
  16:              }
  17:              return sb.ToString();
  18:          }
  19:          /// <summary>
  20:          /// 对文件进行MD5加密
  21:          /// </summary>
  22:          public static string MD5Stream(string filePath)
  23:          {
  24:              using (FileStream stream = File.Open(filePath, FileMode.Open))
  25:              {
  26:                  return MD5Stream(stream); 
  27:              }
  28:          }
  29:      }