C# 获取一个文件的MD5值
2024-09-03 12:13:42
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace ConsoleApplication6
{
public class Program
{
public static void Main(string[] args)
{
string fileName = @"D:\说明.txt";
string result = GetMD5HashFromFile(fileName);
} // <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 = ; i < retVal.Length; i++)
{
sb.Append(retVal[i].ToString("x2"));
}
return sb.ToString();
}
catch (Exception ex)
{
throw new Exception("GetMD5HashFromFile() fail,error:" + ex.Message);
}
}
}
}
最新文章
- 基于Vue2.0的单页面开发方案
- Swift开发小技巧--自定义转场动画
- POJ 1466 Girls and Boys 黑白染色 + 二分匹配 (最大独立集) 好题
- rhythmbox插件开发笔记1:简介&;入门
- 《OD学storm》20160827
- PHP - PDO 之 mysql 事务功能
- Meditation Guide
- c++重点知识点
- unity介绍
- JavaEE学习之设计模式
- 访问Access日期字段
- Luogu 2245 星际导航(最小生成树,最近公共祖先LCA,并查集)
- Android WebView 上传各种文件(包括拍照 录像 录音 文件 音乐 等,用到图片或拍照的,可以参考下)
- python爬虫(二)_HTTP的请求和响应
- Flutter 即学即用系列博客——04 Flutter UI 初窥
- 20145203盖泽双 《网络对抗技术》实践1—— MAL_逆向与Bof基础
- 安装ik分词器以及版本和ES版本的兼容性
- 异步图片下载引擎(升级版——ExecutorService+handler)
- CentOS 中 配置 Nginx 支持 https
- 启动hadoop 2.6遇到的datanode启动不了