zoukankan      html  css  js  c++  java
  • 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);
  • 相关阅读:
    线段树(题集
    T3——拆分自然数
    P1309 瑞士轮
    普通母函数简单使用
    双向广度优先搜索
    秦九韶算法
    P1043-数字游戏
    网站在阿里云备案的详细全过程详细步骤
    从git拉取代码后经常出现maven窗口不见
    SpringBoot入门教程之打成war包在tomcat容器中执行
  • 原文地址:https://www.cnblogs.com/kevinl/p/13726474.html
Copyright © 2011-2022 走看看