System.EncryptHelper.Encrypt C# (CSharp) Method

Encrypt() public static method

基于MD5和秘钥的加密算法
public static Encrypt ( this str, string key = "h%12D;](6" ) : string
str this this
key string 秘钥
return string
        public static string Encrypt(this string str, string key = "h%12D;](6")
        {
            var md5 = MD5.Create();

            // 计算字符串的散列值
            var bytes = md5.ComputeHash(Encoding.UTF8.GetBytes(str));
            var eKey = new StringBuilder();
            foreach (var item in bytes)
            {
                eKey.Append(item.ToString("x"));
            }

            // 字符串散列值+密钥再次计算散列值
            bytes = md5.ComputeHash(Encoding.UTF8.GetBytes(key + eKey));
            var pwd = new StringBuilder();
            foreach (var item in bytes)
            {
                pwd.Append(item.ToString("x"));
            }

            return pwd.ToString();
        }