zoukankan      html  css  js  c++  java
  • 生成MD5加密

          /// <summary>
            /// MD5加密
            /// </summary>
            /// <param name="str"></param>
            /// <returns></returns>
            public static string CalcMD5(this string str)
            {
                byte[] bytes = System.Text.Encoding.UTF8.GetBytes(str);
                return CalcMD5(bytes);
            }
            public static string CalcMD5(byte[] bytes)
            {
                using (MD5 md5 = MD5.Create())
                {
                    byte[] computeBytes = md5.ComputeHash(bytes);
                    string result = "";
                    for (int i = 0; i < computeBytes.Length; i++)
                    {
                        result += computeBytes[i].ToString("X").Length == 1 ? "0" + computeBytes[i].ToString("X") : computeBytes[i].ToString("X");
                    }
                    return result;
    
                }
    
            }
            public static string CalcMD5(Stream stream)
            {
                using (MD5 md5 = MD5.Create())
                {
                    byte[] computeBytes = md5.ComputeHash(stream);
                    string result = "";
                    for (int i = 0; i < computeBytes.Length; i++)
                    {
                        result += computeBytes[i].ToString("X").Length == 1 ? "0" +
                        computeBytes[i].ToString("X") : computeBytes[i].ToString("X");
                    }
                    return result;
                }
            }
  • 相关阅读:
    P4999 烦人的数学作业
    P3413 SAC#1
    P2657 [SCOI2009]windy数
    P2602 [ZJOI2010]数字计数
    JSOI2007 建筑抢修
    CF161B Discounts
    Description
    Street Numbers
    Pizza Cutting
    Supermean
  • 原文地址:https://www.cnblogs.com/lbjcoder/p/8386232.html
Copyright © 2011-2022 走看看