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;
        }
原文地址:https://www.cnblogs.com/fengyun99/p/1710372.html