当前位置:网站首页>C# 一行代码计算文件的MD5值 - CodePlus系列
C# 一行代码计算文件的MD5值 - CodePlus系列
2022-07-01 09:51:00 【猿长大人】
C# 一行代码计算文件的MD5值
前言
MD5信息摘要算法(英语:MD5 Message-Digest Algorithm),一种被广泛使用的密码散列函数,可以产生出一个128位(16字节)的散列值(hash value),用于确保信息传输完整一致。
我们在做开发的过程中经常会遇到计算文件MD5的场景。如何简单高效的一行代码获取MD5值呢?我们来一起看看吧!
引入CodePlus
对着项目右键,选择管理NuGet程序包
在搜索栏中输入CodePlus,选择图中的程序包后,选择安装即可。

示例代码
获取MD5字节数组
var md5 = new FileInfo(@"D:\pic.png").GetMD5();
获取MD5字符串
var md5 = new FileInfo(@"D:\pic.png").GetMD5().ToHexString();
获取MD5的其他相关方法
// 获取小文件的MD5
var md5 = new FileInfo(@"D:\pic.png").GetMD5ForSmallFile().ToHexString();
// 获取大文件的MD5
var md5 = new FileInfo(@"D:\pic.png").GetMD5ForLargeFile().ToHexString();
// 自动选择(大于10MB会执行GetMD5ForLargeFile,小于等于10MB会执行GetMD5ForSmallFile)
var md5 = new FileInfo(@"D:\pic.png").GetMD5().ToHexString();
边栏推荐
- 遇到女司机业余开滴滴,日入500!
- Fried money, lost 10million.
- BSN long story 10: how to ensure the safety of NFT
- Can you afford to buy a house in Beijing, Shanghai, Guangzhou and Shenzhen with an annual salary of 1million?
- 好高的佣金,《新程序员》合伙人计划来袭,人人皆可参与!
- Initial experience of Flink, a mainstream real-time stream processing computing framework
- Centos 配置discuz 提示请检查 mysql 模块是否正确加载
- Problems caused by delete and delete[]
- SQL学习笔记(02)——数据库表操作
- Swift control encapsulation - paging controller
猜你喜欢

【黑马早报】俞敏洪称从来不看新东方股价;恒驰5将于7月开启预售;奈雪虚拟股票或涉嫌非法集资;7月1日起冰墩墩停产...

Flinkv1.13实现金融反诈骗案例

IPv6 learning notes

年薪100万,在北上广深买的起房子吗?

Concept of digital currency

scratch大鱼吃小鱼 电子学会图形化编程scratch等级考试二级真题和答案解析2022年6月

我喜欢两个男人。。。

Module 9: design e-commerce seckill system

Cortex M4 systick details

TC8:UDP_ USER_ INTERFACE_ 01-08
随机推荐
PHP array functions (merge, split, append, find, delete, etc.)
“中移链”国密引擎在BSN正式上线
How to understand JS promise
Wechat emoticons are written into the judgment, and the OK and bomb you send may become "testimony in court"
Postgraduate entrance examination vocabulary 2023 sharing (1)
Mikrotik Routeros Internet access settings
The programmer was beaten.
How Kolo enables NFT music industry
编写自己的who命令
Dspic30f6014a LCD block display
The latest masterpiece of Alibaba, which took 182 days to produce 1015 pages of distributed full stack manual, is so delicious
sql语句修改字段类型「建议收藏」
SQL 化是 ETL 增量生产的第一步,这样的架构的核心能力是什么?
Who has the vision to cross the cycle?
CSDN一站式云服务开放内测,诚邀新老用户来抢鲜
Swag init error: cannot find type definition: response Response
Upload labs for file upload - white box audit
Weidongshan board compilation kernel problem solving
Hardware midrange project
华为帐号多端协同,打造美好互联生活

