c#校验主程序本身的MD5

System.IO System.Security.Cryptography

protected string GetMD5HashFromFile(string fileName)
{
using (var md5 = MD5.Create())
{
using (var stream = File.OpenRead(filename))
{
return BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", string.Empty);
}
}
}

public static class Algorithms
{
  public static readonly HashAlgorithm MD5 = new MD5CryptoServiceProvider();
  public static readonly HashAlgorithm SHA1 = new SHA1Managed();
  public static readonly HashAlgorithm SHA256 = new SHA256Managed();
  public static readonly HashAlgorithm SHA384 = new SHA384Managed();
  public static readonly HashAlgorithm SHA512 = new SHA512Managed();
  public static readonly HashAlgorithm RIPEMD160 = new RIPEMD160Managed();
}

public static string GetHashFromFile(string fileName, HashAlgorithm algorithm)
{
  using (var stream = new BufferedStream(File.OpenRead(fileName), 100000))
  {
    return BitConverter.ToString(algorithm.ComputeHash(stream)).Replace("-", string.Empty);
  }
}


string checksumMd5 = GetChecksum(path, Algorithms.MD5);
string checksumSha1 = GetChecksum(path, Algorithms.SHA1);
string checksumSha256 = GetChecksum(path, Algorithms.SHA256);
string checksumSha384 = GetChecksum(path, Algorithms.SHA384);
string checksumSha512 = GetChecksum(path, Algorithms.SHA512);
string checksumRipemd160 = GetChecksum(path, Algorithms.RIPEMD160);
原文地址:https://www.cnblogs.com/kevinl/p/13726474.html