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);
  • 相关阅读:
    jvm内存分部
    vue 浏览器滚动行为
    vue中vueRouter使用
    vue脚手架的安装和使用
    vue 在路由中复用组件
    单例模式
    ser2net使用
    怎样使用万用表来测试板子上的TX和RX引脚
    STM32W芯片的JTAG口用于GPIO
    openwrt构建过程探索
  • 原文地址:https://www.cnblogs.com/kevinl/p/13726474.html
Copyright © 2011-2022 走看看