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);
  • 相关阅读:
    mysql表结构转hive表结构,字段映射脚本
    kafka 相关命令 偏移重置
    Specified key was too long; max key length is 767 bytes
    java IO 流关系图谱
    jvm 性能监控与linux常用命令
    jupiter的@TempDir 等不生效
    mysql 深度分页
    jedis的ShardedJedisPool链接池的扩容问题
    拜读《三国》看懂男人
    linux 性能优化
  • 原文地址:https://www.cnblogs.com/kevinl/p/13726474.html
Copyright © 2011-2022 走看看