用MD5比较两文件是否相等

public static bool CompareFile(string strSource, string strTarget)
{
using (HashAlgorithm hash = HashAlgorithm.Create())
{
using (FileStream file1 = new FileStream(strSource, FileMode.Open), file2 = new FileStream(strTarget, FileMode.Open))
{
using (MD5 md5_1 = new MD5CryptoServiceProvider(), md5_2 = new MD5CryptoServiceProvider())
{
byte[] hashByte1 = md5_1.ComputeHash(file1);
byte[] haahByte2 = md5_2.ComputeHash(file2);
string str1 = BitConverter.ToString(hashByte1);
string str2 = BitConverter.ToString(haahByte2);
return (str1 == str2);
}
}
}
}

posted @ 2016-05-25 17:16  dlmuzjq  阅读(1547)  评论(0编辑  收藏  举报