我有一个文件mytextfile.txt,其校验和为:“ 81b89b1908e3b3b7fcd7526810c32f14”。当我将该文件从PC移至MacBook并进行检查时,得到“ e97f28bfff174f9643c088814377ada6”。有人知道为什么吗?
/// <summary>
/// Making sure our mapfiles are not tampered with by calculating the checksum
/// Source: https://stackoverflow.com/questions/10520048/calculate-md5-checksum-for-a-file
/// Source: https://en.wikipedia.org/wiki/MD5
/// </summary>
/// <param name="filename"></param>
public string CheckMD5(string filename)
{
// "using": automatically disposes the object after use,
// even if exception is casted
using (var md5 = MD5.Create())
{
using (var stream = File.OpenRead(filename))
{
var hash = md5.ComputeHash(stream);
return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
}
}
}
也很抱歉,如果我没有使用哈希和校验和一词正确的话,仍然不太了解何时使用哈希和何时使用校验和。我可以说我的哈希是:“ 123123”吗?