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

  • 相关阅读:
    css3小叮当(转载)
    三大Flex布局用法(转载)
    移动前端:移动端页面坑与排坑技巧
    最好的前端开发资源推荐(转载)
    高效CSS开发核心要点摘录
    css常用代码大全以及css兼容(转载)
    如何处理CSS3属性前缀(转载)总结
    前端制作入门知识(转载)
    移动前端页面制作技巧(一)转载
    sass揭秘之@mixin,%,@function(转载)
  • 原文地址:https://www.cnblogs.com/houzuofeng/p/3253187.html
Copyright © 2020-2023  润新知