首页 > 代码库 > AES 加密 解密
AES 加密 解密
/// <summary> /// AES 加密 /// </summary> /// <param name="input">待加密的字符串</param> /// <param name="key">加密密钥,要求为32位</param> /// <returns>加密成功返回加密后的字符串,失败 throw</returns> public static string EncryptAES(string CallPassword, string input, string key) { if (CallPassword != GetCallCert()) return ""; byte[] inputData =http://www.mamicode.com/ UTF8Encoding.UTF8.GetBytes(input); RijndaelManaged rijndaelProvider = new RijndaelManaged(); rijndaelProvider.Key = UTF8Encoding.UTF8.GetBytes(key.Substring(0, 32)); rijndaelProvider.IV = AES_IV; ICryptoTransform rijndaelEncrypt = rijndaelProvider.CreateEncryptor(); byte[] encryptedData = http://www.mamicode.com/rijndaelEncrypt.TransformFinalBlock(inputData, 0, inputData.Length); return Convert.ToBase64String(encryptedData); } /// <summary> /// AES 解密 /// </summary> /// <param name="input">待解密的字符串</param> /// <param name="key">解密密钥,要求为32位,和加密密钥相同</param> /// <returns>解密成功返回解密后的字符串,失败 throw</returns> public static string DecryptAES(string CallPassword, string input, string key) { if (CallPassword != GetCallCert()) return ""; byte[] inputData =http://www.mamicode.com/ Convert.FromBase64String(input); RijndaelManaged rijndaelProvider = new RijndaelManaged(); rijndaelProvider.Key = UTF8Encoding.UTF8.GetBytes(key.Substring(0, 32)); rijndaelProvider.IV = AES_IV; ICryptoTransform rijndaelDecrypt = rijndaelProvider.CreateDecryptor(); byte[] decryptedData = http://www.mamicode.com/rijndaelDecrypt.TransformFinalBlock(inputData, 0, inputData.Length); return UTF8Encoding.UTF8.GetString(decryptedData); }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。