zoukankan      html  css  js  c++  java
  • 计算md5的值

     /// <summary>         /// 得到字符串的MD5散列值         /// </summary>         /// <param name="input"></param>         /// <returns></returns>        

    public static String GetMD5(this string input)       

      {         

        System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();            

    byte[] bs = System.Text.Encoding.UTF8.GetBytes(input);       

          bs = x.ComputeHash(bs);           

      System.Text.StringBuilder s = new System.Text.StringBuilder();       

          foreach (byte b in bs)        

         {              

       s.Append(b.ToString("x2").ToLower());         

        }            

    return s.ToString();     

        }

            /// <summary>         /// 计算文件的MD5值         /// </summary>         /// <param name="filepath"></param>         /// <returns></returns>         public static String GetStreamMD5(Stream stream)         {             string strResult = "";             string strHashData = "";             byte[] arrbytHashValue;             System.Security.Cryptography.MD5CryptoServiceProvider oMD5Hasher =                 new System.Security.Cryptography.MD5CryptoServiceProvider();             arrbytHashValue = oMD5Hasher.ComputeHash(stream); //计算指定Stream 对象的哈希值             //由以连字符分隔的十六进制对构成的String,其中每一对表示value 中对应的元素;例如“F-2C-4A”             strHashData = System.BitConverter.ToString(arrbytHashValue);             //替换-             strHashData = strHashData.Replace("-", "");             strResult = strHashData;             return strResult;         }

  • 相关阅读:
    centos下网络的基本配置方法讲解
    win8.1环境下硬盘安装centos6.5双系统
    新人出世
    Docker 仓库管理
    Docker Dockerfile
    Docker image创建之Hello world
    ASP.Net Core 发布到 Centos Docker
    C# 人工智能
    C#使用ML.Net完成人工智能预测
    无监督和有监督算法的区别
  • 原文地址:https://www.cnblogs.com/msdncrazy/p/3021291.html
Copyright © 2011-2022 走看看