Exemplo n.º 1
0
Arquivo: MD5.cs Projeto: mbsky/albian
        /// <summary>
        /// MD5加密字符串.
        /// </summary>
        /// <param name="input">需要加密的字符串.</param>
        /// <param name="bit">加密的位数.</param>
        /// <param name="isUpper">加密的结果是否需要大写.</param>
        /// <returns>经过MD5加密的字符串</returns>
        public static string Encrypt(string input, MD5Mode bit, bool isUpper)
        {
            var md5 = new MD5CryptoServiceProvider();
            byte[] data = md5.ComputeHash(Encoding.Default.GetBytes(input));
            var stringBuilder = new StringBuilder();

            switch (bit)
            {
                case MD5Mode.Low:
                    {
                        for (int i = 4; i <= 11; i++)
                        {
                            stringBuilder.Append(data[i].ToString("x2"));
                        }
                        break;
                    }
                case MD5Mode.High:
                    {
                        for (int i = 0; i <= 15; i++)
                        {
                            stringBuilder.Append(data[i].ToString("x2"));
                        }
                        break;
                    }
            }
            if (isUpper)
                return stringBuilder.ToString().ToUpper();
            return stringBuilder.ToString().ToLower();
        }
Exemplo n.º 2
0
        /// <summary>
        /// MD5加密字符串.
        /// </summary>
        /// <param name="input">需要加密的字符串.</param>
        /// <param name="bit">加密的位数.</param>
        /// <param name="isUpper">加密的结果是否需要大写.</param>
        /// <returns>经过MD5加密的字符串</returns>
        public override string MD5(string input, MD5Mode bit)
        {
            var md5 = new MD5CryptoServiceProvider();

            byte[] data          = md5.ComputeHash(Encoding.Default.GetBytes(input));
            var    stringBuilder = new StringBuilder();

            switch (bit)
            {
            case MD5Mode.Low:
            {
                for (int i = 4; i <= 11; i++)
                {
                    stringBuilder.Append(data[i].ToString("x2"));
                }
                break;
            }

            case MD5Mode.High:
            {
                for (int i = 0; i <= 15; i++)
                {
                    stringBuilder.Append(data[i].ToString("x2"));
                }
                break;
            }
            }
            return(stringBuilder.ToString());
        }
Exemplo n.º 3
0
 public static string Encrypt(string str, MD5Mode mode = MD5Mode.Strongly)
 {
     using (System.Security.Cryptography.MD5CryptoServiceProvider _md5Provider = new System.Security.Cryptography.MD5CryptoServiceProvider())
     {
         byte[] bytes = EncodingUtility.get_bytes(str, Encoding.UTF8);
         bytes = _md5Provider.ComputeHash(bytes);
         StringBuilder _sb = new StringBuilder();
         int s, e;
         s = mode == MD5Mode.Strongly ? 0 : 4;
         e = mode == MD5Mode.Strongly ? 16 : 12;
         for (int i = s; i < e; i++)
             _sb.Append(bytes[i].ToString("X2"));
         bytes = null;
         return _sb.ToString();
     }
 }
Exemplo n.º 4
0
 public abstract string MD5(string input, MD5Mode bit);
Exemplo n.º 5
0
 public abstract string MD5(string input, MD5Mode bit, bool isUpper);
Exemplo n.º 6
0
 public abstract string MD5(string input, MD5Mode bit);
Exemplo n.º 7
0
 public abstract string MD5(string input, MD5Mode bit, bool isUpper);