当前位置:网站首页>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();
边栏推荐
- leetcode:111. 二叉树的最小深度
- Voice service notes
- What is cloud primordial? Will it be the trend of future development?
- 谁拥有穿越周期的眼光?
- Dspic30f6014a LCD block display
- Rich text interpolation
- Raspberry pie 4B system construction (ultra detailed version)
- The latest masterpiece of Alibaba, which took 182 days to produce 1015 pages of distributed full stack manual, is so delicious
- High precision factorial
- 遇到女司机业余开滴滴,日入500!
猜你喜欢
日本教授起诉英特尔FPGA与SoC产品侵犯一项设计专利
年薪100万,在北上广深买的起房子吗?
I like two men...
Sleeping second brother...
PHP code audit and File Inclusion Vulnerability
Module 9: design e-commerce seckill system
Scratch big fish eat small fish Electronic Society graphical programming scratch grade examination level 2 true questions and answers analysis June 2022
HMS Core音频编辑服务3D音频技术,助力打造沉浸式听觉盛宴
HMS core audio editing service 3D audio technology helps create an immersive auditory feast
A quietly rising domestic software, low-key and powerful!
随机推荐
SQL statement modify field type "suggestions collection"
项目采购管理
HMS core audio editing service 3D audio technology helps create an immersive auditory feast
渗透常用工具-Goby
Write your own who commands
Postgraduate entrance examination vocabulary 2023 sharing (1)
Mikrotik Routeros Internet access settings
CSDN's one-stop cloud service is open for internal testing, and new and old users are sincerely invited to grab the fresh
[unity shader] substitution of bool type in the property definition
好高的佣金,《新程序员》合伙人计划来袭,人人皆可参与!
SQL学习笔记(01)——数据库基本知识
Spark's action operator
全球基金和资管的股票建仓率达到15年内新低
Network partition notes
I like two men...
Who has the vision to cross the cycle?
奇怪,为什么ArrayList初始化容量大小为10?
Construction of esp8266 FreeRTOS development environment
scratch大鱼吃小鱼 电子学会图形化编程scratch等级考试二级真题和答案解析2022年6月
123. how to stop a thread?