Example #1
0
        /// <summary>
        /// 加密
        /// </summary>
        /// <param name="value">待加密的值</param>
        /// <param name="key">密钥</param>
        /// <param name="iv">加密偏移量</param>
        /// <returns></returns>
        public override string Encrypt(string value, string key, string iv = null)
        {
            var result = RC4EncryptionProvider.Encrypt(Encoding.GetBytes(value), Encoding.GetBytes(key));

            if (OutType == OutType.Base64)
            {
                return(Convert.ToBase64String(result));
            }
            return(result.ToHexString());
        }
Example #2
0
        /// <summary>
        /// 解密
        /// </summary>
        /// <param name="value">待解密的值</param>
        /// <param name="key">密钥</param>
        /// <param name="iv">加密偏移量</param>
        /// <param name="outType">输出类型,默认为<see cref="OutType.Base64"/></param>
        /// <param name="encoding">编码类型,默认为<see cref="Encoding.UTF8"/></param>
        /// <returns></returns>
        public override string Decrypt(string value, string key, string iv = null)
        {
            var result = RC4EncryptionProvider.Decrypt(value.GetEncryptBytes(OutType), Encoding.GetBytes(key));

            return(Encoding.GetString(result));
        }