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;         }

  • 相关阅读:
    Python简介
    名词术语 1
    TypeError: 'method' object is not subscriptable 一般是函数没加括号导致的
    MYSQL 使用命令行导入文本数据 csv数据
    日期函数格式化
    日期函数——第几天、第几周、星期几、第几季度
    日期函数——MYSQL
    集合常见面试题
    输入一个随机整数,输出对应的大写
    Oracle数据库基本sql语句
  • 原文地址:https://www.cnblogs.com/msdncrazy/p/3021291.html
Copyright © 2011-2022 走看看