Ejemplo n.º 1
0
        public void Crypto()
        {
            var encData = aes.Encrypt("1");
            var str     = aes.Decrypt(encData, mode: CipherMode.ECB);

            Assert.AreEqual("1", str);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// AES解密
        /// </summary>
        /// <param name="aes"></param>
        /// <param name="str">待解密的字符串(base64编码格式)</param>
        /// <param name="encoding">解密后字符串编码格式</param>
        /// <param name="key">解密密钥,为空则使用实体属性Key</param>
        /// <param name="mode">解密模式,为空则使用实体属性Mode</param>
        /// <param name="padding">填充算法,为空则使用实体属性Padding</param>
        /// <returns>解密字符串</returns>
        public static string Decrypt(this System.Security.Cryptography.Aes aes,
                                     string str, Encoding encoding, byte[] key = null, CipherMode?mode = null, PaddingMode?padding = null)
        {
            var data    = Convert.FromBase64String(str);
            var encData = aes.Decrypt(data, key, mode, padding);

            return(encoding.GetString(encData));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// AES解密
 /// </summary>
 /// <param name="aes"></param>
 /// <param name="str">待解密的字符串(base64编码格式)</param>
 /// <param name="key">解密密钥,为空则使用实体属性Key</param>
 /// <param name="mode">解密模式,为空则使用实体属性Mode</param>
 /// <param name="padding">填充算法,为空则使用实体属性Padding</param>
 /// <returns>UTF8编码格式解密字符串</returns>
 public static string Decrypt(this System.Security.Cryptography.Aes aes,
                              string str, byte[] key = null, CipherMode?mode = null, PaddingMode?padding = null)
 {
     return(aes.Decrypt(str, Encoding.UTF8, key, mode, padding));
 }