Conris.Utility/MD5Helper.cs
(开头部分) 5KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Security.Cryptography;
namespace Conris.Utility
{
public static class MD5Helper
{
private static readonly int BufferSize = 1048576;//1M
/// <summary>
/// 实现对一个文件md5的读取,path为文件路径
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public static string md5_hash(string path)
{
string hash = null;
try
{
//using (var fs = File.OpenRead(path))
using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, BufferSize))
{
using (var get_file = new BufferedStream(fs, BufferSize))
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
byte[] hash_byte = md5.ComputeHash(get_file);
hash = ToHashCode(hash_byte);
get_file.Close();
md5.Clear();
fs.Close();
}
}
}
catch (Exception e)
{
Log4netHelper.Error(path + " 计算MD5时发生错误", e);
}
return hash;
}
/// <summary>
/// 实现对一个文件md5的读取,path为文件路径
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
//public static string GetHash(string path)
//{
// string hash = null;
// try
// {
// using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, BufferSize))
// {
// MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
// byte[] hash_byte = md5.ComputeHash(fs);
// hash = ToHashCode(hash_byte);
// md5.Clear();
后面还有 114 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
