/// <summary> /// AES加密方法(AES加密和Base64混合加密) /// </summary> /// <param name="toEncrypt"></param> /// <returns></returns> public static string Encrypt(string content, string InsureKey) { string toEncrypt = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(content, "MD5").ToLower(); //指定InsureKey做MD5加密并作截取(C#截取8到16)获得加密的key作为密钥 string key = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(InsureKey, "MD5").Substring(8, 16).ToLower(); byte[] keyArray = UTF8Encoding.UTF8.GetBytes(key); byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(toEncrypt); RijndaelManaged rDel = new RijndaelManaged(); rDel.Key = keyArray; rDel.Mode = CipherMode.ECB; rDel.Padding = PaddingMode.PKCS7; ICryptoTransform cTransform = rDel.CreateEncryptor(); byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length); return Convert.ToBase64String(resultArray).Replace("+", "%2B"); }