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;
            }
  • 相关阅读:
    csp 通信网络
    从客户端(content="xxxxx")中检测到有潜在危险的 Request.Form 值——较合理解决方案
    HttpUtility.HtmlEncode 方法
    web程序防止攻击的一些资料——整理
    memcached——学习
    VS2015 无法启动IIS Express Web服务器
    文件上传——资料收集
    水晶报表-需要安装软件
    web安全漏洞相关
    javascript一个在网页上画线的库
  • 原文地址:https://www.cnblogs.com/fengyun99/p/1710372.html
Copyright © 2011-2022 走看看