zoukankan      html  css  js  c++  java
  • C# 生成MD5编码方法(不同位数)

            /// <summary> 
            /// </summary> 
            /// <param name="strSource">待加密字串</param> 
            /// <returns>加密后的字串</returns> 
            public static string MD5Encrypt(string strSource)
            {
                return MD5Encrypt(strSource, 32);
            }

            /// <summary> 
            /// </summary> 
            /// <param name="strSource">待加密字串</param> 
            /// <param name="length">16或32值之一,其它则采用.net默认MD5加密算法</param> 
            /// <returns>加密后的字串</returns> 
            public static string MD5Encrypt(string strSource, int length)
            {
                byte[] bytes = Encoding.ASCII.GetBytes(strSource);
                byte[] hashValue = ((System.Security.Cryptography.HashAlgorithm)System.Security.Cryptography.CryptoConfig.CreateFromName("MD5")).ComputeHash(bytes);
                StringBuilder sb = new StringBuilder();
                switch (length)
                {
                    case 16:
                        for (int i = 4; i < 12; i++)
                            sb.Append(hashValue[i].ToString("x2"));
                        break;
                    case 32:
                        for (int i = 0; i < 16; i++)
                        {
                            sb.Append(hashValue[i].ToString("x2"));
                        }
                        break;
                    default:
                        for (int i = 0; i < hashValue.Length; i++)
                        {
                            sb.Append(hashValue[i].ToString("x2"));
                        }
                        break;
                }
                return sb.ToString();
            } 

  • 相关阅读:
    sqlalchemy访问Oracle数据库报错:UnicodeDecodeError: 'big5' codec can't decode byte 0xfb in position 2: illegal multibyte sequence
    Mac如何安装FastDfs
    Django执行Sql语句笔记
    跑DRF框架分页源码笔记
    Python Paginator分页学习
    Python Excel笔记
    npm run dev报错解决方法
    npm install --global vue-cli 报错 [..................] / rollbackFailedOptional: verb npm-session abfa82f3041ebc02
    MS17_010漏洞攻击Windows7
    虚拟机启动黑屏
  • 原文地址:https://www.cnblogs.com/houzuofeng/p/3253187.html
Copyright © 2011-2022 走看看