当前位置:网站首页>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();
边栏推荐
- IPv6 learning notes
- The stock position building rate of global funds and asset management reached a new low in 15 years
- SQL学习笔记(02)——数据库表操作
- Sleeping second brother...
- TC8:UDP_USER_INTERFACE_01-08
- 7-Zip boycotted? The callers have committed "three crimes": pseudo open source, unsafe, and the author is from Russia!
- 电脑USB、HDMI、DP各种接口及速度
- Computer USB, HDMI, DP various interfaces and speeds
- 嵌入式开发用到的一些工具
- 日本教授起诉英特尔FPGA与SoC产品侵犯一项设计专利
猜你喜欢

云原生到底是什么?它会是未来发展的趋势吗?

LVGL V8.2字符串显示在Keil MDK上需要注意的事项(以小熊派为例)

TC8:UDP_USER_INTERFACE_01-08

【无标题】

渗透常用工具-Goby

硬件中台项目

Finally, someone made it clear what DRAM and NAND flash are

一个悄然崛起的国产软件,低调又强大!

7-Zip 遭抵制?呼吁者定下“三宗罪”:伪开源、不安全、作者来自俄罗斯!

Tearful eyes, it's not easy to change jobs. Three rounds of interviews, four hours of soul torture
随机推荐
Sleeping second brother...
Rich text interpolation
LVGL V8.2字符串显示在Keil MDK上需要注意的事项(以小熊派为例)
Postgraduate entrance examination vocabulary 2023 sharing (1)
SQL learning notes (03) -- data constraint relationship
BSN长话短说之十:如何保证NFT的安全
Solution of EPS image blur by latex insertion
Weidongshan board compilation kernel problem solving
Centos 配置discuz 提示请检查 mysql 模块是否正确加载
Ssh server rejects password, try again; Permitrootlogin yes invalid problem
High precision factorial
富文本实现插值
Project procurement management
Hololens2 development -6-eyetracking and speech recognition
7-Zip 遭抵制?呼吁者定下“三宗罪”:伪开源、不安全、作者来自俄罗斯!
Can you afford to buy a house in Beijing, Shanghai, Guangzhou and Shenzhen with an annual salary of 1million?
Win11账号被锁定无法登录怎么办?Win11账号被锁定无法登录
CSDN's one-stop cloud service is open for internal testing, and new and old users are sincerely invited to grab the fresh
Initial experience of Flink, a mainstream real-time stream processing computing framework
In terms of use

