当前位置:网站首页>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();
边栏推荐
- CSDN一站式云服务开放内测,诚邀新老用户来抢鲜
- The market is relatively weak recently
- Wechat applet WebView prohibits page scrolling without affecting the implementation of overflow scrolling in the business
- Sleeping second brother...
- LVGL V8.2字符串显示在Keil MDK上需要注意的事项(以小熊派为例)
- Raspberry pie 4B system construction (ultra detailed version)
- 哪个券商公司炒股开户佣金低又安全又可靠
- Drive away bad emotions and stop worrying
- About widthstep of images in opencv
- Hardware midrange project
猜你喜欢

Who has the vision to cross the cycle?

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

Packetdrill script analysis guide

持续进阶,软通动力稳步推动云智能战略

Cortex M4 systick details

The market is relatively weak recently

Tearful eyes, it's not easy to change jobs. Three rounds of interviews, four hours of soul torture

TC8:UDP_ USER_ INTERFACE_ 01-08

Import and export of power platform platform sharepointlist

leetcode:111. 二叉树的最小深度
随机推荐
Win11账号被锁定无法登录怎么办?Win11账号被锁定无法登录
关于OpenCV中图像的widthStep
Tearful eyes, it's not easy to change jobs. Three rounds of interviews, four hours of soul torture
华为帐号多端协同,打造美好互联生活
dotnet 控制台 使用 Microsoft.Maui.Graphics 配合 Skia 进行绘图入门
直播管理项目
超标量处理器设计 姚永斌 第4章 分支预测 --4.1 小节摘录
Introduction to mt7628k eCos development
If you meet a female driver and drive didi as an amateur, you can earn 500 a day!
Sd-wan notes
PHP code audit and File Inclusion Vulnerability
A 419 error occurred in the laravel postman submission form. July 6th, 2020 diary.
Thread Basics
Finally, someone made it clear what DRAM and NAND flash are
MySQL interception_ MySQL method for intercepting strings [easy to understand]
mysql截取_mysql截取字符串的方法[通俗易懂]
SQL学习笔记(02)——数据库表操作
Fried money, lost 10million.
leetcode:111. 二叉树的最小深度
tryhackme圣诞挑战2021-Advent of Cyber 3-day1-IDOR漏洞,不安全的访问控制漏洞

