Exemplo n.º 1
0
        /// <summary>
        /// AES加密
        /// </summary>
        /// <param name="plainStr">明文字符串</param>
        /// <param name="key">密钥</param>
        /// <param name="iv">向量</param>
        /// <returns>密文</returns>
        public static string AESEncrypt(string plainStr, string key, string iv)
        {
            if (string.IsNullOrEmpty(plainStr))
            {
                return(string.Empty);
            }
            MaAES  maCaes  = new MaAES(key, iv);
            string encrypt = maCaes.AESEncrypt(plainStr);

            if (string.IsNullOrEmpty(encrypt))
            {
                return(string.Empty);
            }
            else
            {
                return(StringToBase16(encrypt));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// AES解密
        /// </summary>
        /// <param name="decryptStr">密文字符串</param>
        /// <param name="key">密钥</param>
        /// <param name="iv">向量</param>
        /// <returns>明文</returns>
        public static string AESDecrypt(string decryptStr, string key, string iv)
        {
            decryptStr = Base16ToString(decryptStr);
            if (string.IsNullOrEmpty(decryptStr))
            {
                return(string.Empty);
            }
            MaAES  maCaes  = new MaAES(key, iv);
            string decrypt = maCaes.AESDecrypt(decryptStr);

            if (string.IsNullOrEmpty(decrypt))
            {
                return(string.Empty);
            }
            else
            {
                return(decrypt);
            }
        }