zoukankan      html  css  js  c++  java
  • c# MD5方法总结

         /// <summary>
            /// 32位md5
            /// </summary>
            /// <param name="str"></param>
            /// <returns></returns>
            public static string GetBigMd5(string str)
            {
                string cl = str;
                string pwd = "";
                var md5 = MD5.Create();

                byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(cl));

                for (int i = 0; i < s.Length; i++)
                {
                    pwd = pwd + s[i].ToString("X2");
                }

                return pwd;
            }
            /// <summary>
            /// 16位MD5
            /// </summary>
            /// <param name="str"></param>
            /// <returns></returns>
            public static string GetSmallMd5(string str)
            {
                var md5 = new MD5CryptoServiceProvider();
                string t2 = BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(str)), 4, 8);
                t2 = t2.Replace("-", "");
                return t2;
            }

            private static string Encrypt(string strInput)
            {
                int i;

                int len = strInput.Length;

                string strFont = strInput.Remove(len - 1, 1);
                string strEnd = strInput.Remove(0, len - 1);

                var charFont = strFont.ToCharArray();
                for (i = 0; i < strFont.Length; i++)
                {
                    int intFont = (int)charFont[i] + 3;
                    charFont[i] = Convert.ToChar(intFont);

                }
                strFont = ""; //let strFont  null
                for (i = 0; i < charFont.Length; i++)
                {
                    strFont += charFont[i];
                }
                var strOutput = strEnd + strFont;
                return strOutput;

            }
            private static string Decrypt(string strInput)
            {
                int i;

                string strFont = strInput.Remove(0, 1);
                string strEnd = strInput.Remove(1);

                var charFont = strFont.ToCharArray();
                for (i = 0; i < strFont.Length; i++)
                {
                    int intFont = (int)charFont[i] - 3;
                    charFont[i] = Convert.ToChar(intFont);

                }
                strFont = ""; //let strFont  null
                for (i = 0; i < charFont.Length; i++)
                {
                    strFont += charFont[i];
                }
                string strOutput = strFont + strEnd;
                return strOutput;
            }
  • 相关阅读:
    JAVA实现加入收藏和设为首页---网摘
    oracle序列的创建和使用
    针对Eclipse闪退的两种解决方案
    Mavean多工程依赖项目
    Z_Tree的使用案例(出差地点的演示)
    JAVA将数字钱数转换为大写
    提交表单时,post方式无法提交(一种情况)
    HTML中字体的垂直排列
    按照拼音排序的SQL语句条件
    在jsp里调用out.flush()和response.flushBuffer()有什么区别
  • 原文地址:https://www.cnblogs.com/fengyun99/p/1710372.html
Copyright © 2011-2022 走看看