如何使用C#计算系统中所有文件的MD5值? [英] How do calculate MD5 values of all files in a system using C#?
本文介绍了如何使用C#计算系统中所有文件的MD5值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为系统的所有文件计算MD5。
我尝试了什么:
I want to calculate MD5 for all files of a system.
What I have tried:
using System.IO;
using System.Security.Cryptography;
public static class Algorithms
{
public static readonly HashAlgorithm MD5 = new MD5CryptoServiceProvider();
}
public static string GetChecksum(string filePath, HashAlgorithm algorithm)
{
using (var stream = new BufferedStream(File.OpenRead(filePath), 100000))
{
byte[] hash = algorithm.ComputeHash(stream);
return BitConverter.ToString(hash).Replace("-", String.Empty);
}
}
我用它来计算特定文件。
I am using this to calculate for a particular file.
string path = @"C:\Folder\file.txt";
string checksumMd5 = GetChecksum(path, Algorithms.MD5);
推荐答案
这是正确的方法,操作系统本身没有支持文件哈希注册表
This is the correct approach, there is no file hashing registry supported by the OS natively
这篇关于如何使用C#计算系统中所有文件的MD5值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文