需要用到的类HashAlgorithm
using System.IO;
using System.Security.Cryptography;
using (HashAlgorithm hash = HashAlgorithm.Create())
{
using (FileStream file1 = new FileStream(filePath1, FileMode.Open), file2 = new FileStream(filePath2, FileMode.Open))
{
byte[] hashByte1 = hash.ComputeHash(file1);//计算指定Stream的哈希值
byte[] hashByte2 = hash.ComputeHash(file2);
string str1 = BitConverter.ToString(hashByte1);//将字节数组装换为字符串
string str2 = BitConverter.ToString(hashByte2);
if (str1 == str2)
{
Console.WriteLine("相同");
}
else
{
Console.WriteLine("不同");
}
}