MD5、SHA で両方のファイルをハッシュし、両方の合計が同じかどうかを比較する必要があります。
System.Security.Cryptography で MD5CryptoServiceProvider と SHA512CryptoServiceProvider を確認します。
それは次のようなものです:
private string ComputeHashAsText(byte[] fileBytes)
{
using (SHA512CryptoServiceProvider cryptoService = new SHA512CryptoServiceProvider())
{
return Encoding.ASCII.GetString(cryptoService.ComputeHash(fileBytes));
}
}
public bool CompareFiles(string pathA, string pathB)
{
string hashPathA = ComputeHashAsText(File.ReadAllBytes(pathA));
string hashPathB = ComputeHashAsText(File.ReadAllBytes(pathB));
return hashPathA == hashPathB;
}
実際のソリューションでは、比較するファイルが大きすぎてすべてのバイトをメモリに読み取ってハッシュすることができないため、チャンクなどでハッシュを計算することができます。