C# Large Files MD5 C# 获取大文件MD5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Mail;
using System.Net;
using System.Threading;
using System.IO;
using System.Security.Cryptography; namespace ConsoleApp348
{
class Program
{
static List<String> MD5List = new List<string>();
static string logFullPath = Directory.GetCurrentDirectory() + "\\" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
static void Main(string[] args)
{
string dir = @"C:\Users\Fred\Downloads";
GetFiles(dir);
foreach(var md5 in MD5List)
{
Console.WriteLine(md5);
}
Console.ReadLine();
} static void LogMessage(string msg)
{
lock(logFullPath)
{
using (StreamWriter logWriterStream = new StreamWriter(logFullPath, true, UTF8Encoding.UTF8))
{
logWriterStream.WriteLine($"Log message :{msg},now is {DateTime.Now.ToString("yyyyMMddHHmmssffff")}");
}
}
} static void GetFiles(string dir)
{
string[] allFiles = Directory.GetFiles(dir, "*", SearchOption.TopDirectoryOnly);
Console.WriteLine($"There are totally {allFiles.Length} files in {dir}");
if (allFiles != null && allFiles.Any())
{
for (int i = ; i < allFiles.Length; i++)
{
GenerateMD5ForLargeFiles(allFiles[i]);
}
}
}
static void GenerateMD5ForLargeFiles(string fileName)
{
StringBuilder stringBuilder = new StringBuilder();
using (Stream readStream = File.OpenRead(fileName))
{
using (MD5 bigFileMD5 = MD5.Create())
{
using (MD5CryptoServiceProvider cryptoServiceProvider = new MD5CryptoServiceProvider())
{
byte[] data = cryptoServiceProvider.ComputeHash(readStream);
for (int i = ; i < data.Length; i++)
{
stringBuilder.Append(data[i].ToString("x2"));
}
}
}
}
MD5List.Add(stringBuilder.ToString());
LogMessage(stringBuilder.ToString());
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Mail;
using System.Net;
using System.Threading;
using System.IO;
using System.Security.Cryptography; namespace ConsoleApp348
{
class Program
{
static List<String> MD5List = new List<string>();
static void Main(string[] args)
{
string dir = @"C:\Users\Fred\Downloads";
GetFiles(dir); if(MD5List.Any())
{
Parallel.ForEach(MD5List, x =>
{
Console.WriteLine(x);
});
}
Console.ReadLine();
} static void GetFiles(string dir)
{
string[] allFiles = Directory.GetFiles(dir, "*", SearchOption.TopDirectoryOnly);
Console.WriteLine($"There are totally {allFiles.Length} files in {dir}");
if(allFiles!=null && allFiles.Any())
{
for(int i=;i<allFiles.Length;i++)
{
GenerateMD5ForLargeFiles(allFiles[i]);
}
}
}
static void GenerateMD5ForLargeFiles(string fileName)
{
StringBuilder stringBuilder = new StringBuilder();
using (Stream readStream = File.OpenRead(fileName))
{
using (MD5 bigFileMD5 = MD5.Create())
{
byte[] data = bigFileMD5.ComputeHash(readStream);
for(int i=;i<data.Length;i++)
{
stringBuilder.Append(data[i].ToString("x2"));
}
}
}
MD5List.Add(stringBuilder.ToString());
}
}
static void GenerateMD5ForLargeFiles(string fileName)
{
StringBuilder stringBuilder = new StringBuilder();
using (Stream readStream = File.OpenRead(fileName))
{
using (MD5 bigFileMD5 = MD5.Create())
{
byte[] data = bigFileMD5.ComputeHash(readStream);
for(int i=0;i<data.Length;i++)
{
stringBuilder.Append(data[i].ToString("x2"));
}
}
}
MD5List.Add(stringBuilder.ToString());
}
[ComVisible(true)]
public sealed class MD5CryptoServiceProvider : MD5
Computes the System.Security.Cryptography.MD5 hash value for the input data using
// the implementation provided by the cryptographic service provider (CSP). This
// class cannot be inherited.
C# Large Files MD5 C# 获取大文件MD5的更多相关文章
- Java计算文件MD5值(支持大文件)
import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.securit ...
- 如何用python最快的获取大文件的最后几行
工作中经常会遇到处理日志文件的问题:为了得到日志的最新状态,我们需要获取日志文件的最后部分行来做判断.那么,这种情况下我们应该怎么做呢? 1)常规方法:从前往后依次读取 步骤:open打开日志文件. ...
- 转 这种方法可以免去自己计算大文件md5 的麻烦
using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEditor;using ...
- 基于js-spark-md5前端js类库,快速获取文件Md5值
js-spark-md5是歪果仁开发的东西,有点多,但是我们只要一个js文件即可,具体类包我存在自己的oschina上,下载地址:https://git.oschina.net/jianqingwan ...
- Vue.js实现大文件分片md5断点续传
背景 根据部门的业务需求,需要在网络状态不良的情况下上传很大的文件(1G+).其中会遇到的问题:1,文件过大,超出服务端的请求大小限制:2,请求时间过长,请求超时:3,传输中断,必须重新上传导致前功尽 ...
- ios获取文件MD5值
一般我们在使用http或者socket上传或者下载文件的时候,经常会在完成之后经行一次MD5值得校验(尤其是在断点续传的时候用的更 多),校验MD5值是为了防止在传输的过程当中丢包或者数据包被篡改,在 ...
- php解决大文件断点续传
核心原理: 该项目核心就是文件分块上传.前后端要高度配合,需要双方约定好一些数据,才能完成大文件分块,我们在项目中要重点解决的以下问题. * 如何分片: * 如何合成一个文件: * 中断了从哪个分片开 ...
- php使用WebUploader做大文件的分块和断点续传
核心原理: 该项目核心就是文件分块上传.前后端要高度配合,需要双方约定好一些数据,才能完成大文件分块,我们在项目中要重点解决的以下问题. * 如何分片: * 如何合成一个文件: * 中断了从哪个分片开 ...
- B/S架构大文件上传问题
核心原理: 该项目核心就是文件分块上传.前后端要高度配合,需要双方约定好一些数据,才能完成大文件分块,我们在项目中要重点解决的以下问题. * 如何分片: * 如何合成一个文件: * 中断了从哪个分片开 ...
随机推荐
- sql server 列字段拼接 —— STUFF
原始数据: sql语句 SELECT DISTINCT l.family_id, )) ,,'' ) isc_id FROM dbo.Addresses l 结果数据:
- Web前端基础(6):CSS(三)
1. 定位 定位有三种:相对定位.绝对定位.固定定位 1.1 相对定位 现象和使用: 1.如果对当前元素仅仅设置了相对定位,那么与标准流的盒子什么区别. 2.设置相对定位之后,我们才可以使用四个方向的 ...
- Java --Lamda表达式
Lamda:属于函数式编程的概念: interface IMessage { public void print() ; } public class TestDemo { public static ...
- PWA入门:手把手教你制作一个PWA应用
摘要: PWA图文教程 原文:PWA入门:手把手教你制作一个PWA应用 作者:MudOnTire Fundebug经授权转载,版权归原作者所有. 简介 Web前端的同学是否想过学习app开发,以弥补自 ...
- zsh: command not found: 解决方法
问题原有:mac中安装了my zsh [https://www.cnblogs.com/dadonggg/p/11027454.html] ,但是造成了在使用vscode的时候,提示”zsh: com ...
- SQL注入漏洞技术的详解
SQL注入漏洞详解 目录 SQL注入的分类 判断是否存在SQL注入 一:Boolean盲注 二:union 注入 三:文件读写 四:报错注入 floor报错注入 ExtractValue报错注入 Up ...
- CodeForces - 1228C(质因数分解+贡献法)
题意 https://vjudge.net/problem/CodeForces-1228C 首先先介绍一些涉及到的定义: 定义prime(x)表示x的质因子集合.举例来说,prime(140)={2 ...
- selenium截取元素
http://www.mamicode.com/info-detail-2161474.html 常见问题 https://blog.csdn.net/u010616442/article/detai ...
- you have new mail in /var/spool/mail/root !
今天开发的同事告诉我,他在登录系统时老是提示you have new mail in /var/spool/mail/root ! 我一猜就知道他们肯定又自己写定时任务了,这样的事已经发生过好几回了, ...
- [C11] 推荐系统(Recommender Systems)
推荐系统(Recommender Systems) 问题阐述(Problem Formulation) 将 推荐系统 纳入这门课程来讲有以下两个原因: 第一.仅仅因为它是机器学习中的一个重要的应用.在 ...