基本信息
源码名称:C# 获取文件md5值(用于检测文件完整性)
源码大小:0.19M
文件格式:.zip
开发语言:C#
更新时间:2018-09-27
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
此实例是C#版本,java版本在这里 https://www.haolizi.net/example/view_16701.html
此实例是C#版本,java版本在这里 https://www.haolizi.net/example/view_16701.html
using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Text;
namespace FileMd5Demo
{
class Program
{
static void Main(string[] args)
{
var filePath = "D:\\Projects\\BullSoftProjects\\smarthome\\smarthome_pictureframe\\app\\release\\app-release - 副本.apk";
var md5 = FileUtil.GetMD5HashFromFile(filePath);
Console.WriteLine($"文件的md5:{md5}");
Console.ReadLine();
}
}
public class FileUtil
{
public static string GetMD5HashFromFile(string fileName)
{
try
{
FileStream file = new FileStream(fileName, System.IO.FileMode.Open);
MD5 md5 = new MD5CryptoServiceProvider();
byte[] retVal = md5.ComputeHash(file);
file.Close();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < retVal.Length; i )
{
sb.Append(retVal[i].ToString("x2"));
}
return sb.ToString();
}
catch (Exception ex)
{
throw new Exception("GetMD5HashFromFile() fail,error:" ex.Message);
}
}
}
}