当前位置:网站首页>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
- Click the screen with your finger to simulate F11 and enter the full screen
- 【无标题】
- Huawei accounts work together at multiple ends to create a better internet life
- 【leetcode】287. Find duplicates
- STM32 inverter power supply design scheme, based on STM32F103 controller [easy to understand]
- In terms of use
- Weidongshan board compilation kernel problem solving
- Fried money, lost 10million.
- Voice service notes
猜你喜欢

Swag init error: cannot find type definition: response Response

Precautions for lvgl v8.2 string display on keil MDK (take little bear pie as an example)

What is cloud primordial? Will it be the trend of future development?

Initial experience of Flink, a mainstream real-time stream processing computing framework

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

谁拥有穿越周期的眼光?
![[fxcg] large scale job hopping may be one of the driving forces behind the soaring inflation in the United States](/img/f6/be4e1affb9568acdedb94117b9b037.jpg)
[fxcg] large scale job hopping may be one of the driving forces behind the soaring inflation in the United States

京东与腾讯续签三年战略合作协议;起薪涨至26万元!韩国三星SK争相加薪留住半导体人才;Firefox 102 发布|极客头条...

uniapp微信小程序组件按需引入

Who has the vision to cross the cycle?
随机推荐
TC8:UDP_USER_INTERFACE_01-08
I like two men...
《天天数学》连载55:二月二十四日
历史上的今天:九十年代末的半导体大战;冯·诺依曼发表第一份草案;CBS 收购 CNET...
Ubuntu系统安装与配置MySQL
谁还在买“三只松鼠”们
The programmer was beaten.
[unity shader] substitution of bool type in the property definition
The latest masterpiece of Alibaba, which took 182 days to produce 1015 pages of distributed full stack manual, is so delicious
数据中台咋就从“小甜甜”变成了“牛夫人”?
Concept of digital currency
[fxcg] large scale job hopping may be one of the driving forces behind the soaring inflation in the United States
Scratch big fish eat small fish Electronic Society graphical programming scratch grade examination level 2 true questions and answers analysis June 2022
Click the screen with your finger to simulate F11 and enter the full screen
JS use toString to distinguish between object and array
PHP 字符串与二进制相互转换
UE small knowledge point controller possess pawn process
好高的佣金,《新程序员》合伙人计划来袭,人人皆可参与!
MapReduce programming basics
年薪100万,在北上广深买的起房子吗?

