Esempio n. 1
0
        /// <summary>
        /// 加密字符串。
        /// </summary>
        /// <param name="str">要加密的字符串。</param>
        /// <param name="key">安全密钥。</param>
        /// <returns>返回 <see cref="string"/> 。</returns>
        public static string Encrypt(string str, string key)
        {
            var x = new XXTEAManaged(key);
            var e = Encoding.UTF8;
            var b = x.Encrypt(e.GetBytes(str), e.GetBytes(x.Key));

            return(Convert.ToBase64String(b));
        }
Esempio n. 2
0
        /// <summary>
        /// 解密字符串。
        /// </summary>
        /// <param name="str">要解密的字符串。</param>
        /// <param name="key">安全密钥。</param>
        /// <returns>返回 <see cref="string"/> 。</returns>
        public static string Decrypt(string str, string key)
        {
            if (string.IsNullOrWhiteSpace(str))
            {
                return(string.Empty);
            }

            var encoding = Encoding.UTF8;
            var x        = new XXTEAManaged(key);

            return(encoding.GetString(x.Decrypt(Convert.FromBase64String(str), encoding.GetBytes(x.Key))));
        }