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

  • 相关阅读:
    LAB8 android
    python3速查参考- python基础 1 -> python版本选择+第一个小程序
    selenium三种断言以及异常类型
    selenium+java:获取列表中的值
    selenium测试(Java)--元素操作(五)
    redhat网卡设置
    PYTHON TDD学习(一)-->Python 3.4版本环境安装Django及其启动
    渗透测试
    实用--功能测试方法与实际测试内容
    SQL常见面试题(学生表_课程表_总表)
  • 原文地址:https://www.cnblogs.com/houzuofeng/p/3253187.html
Copyright © 2011-2022 走看看