1 /// <summary> 2 /// 加解密 3 /// </summary> 4 public class AesCode { 5 #region 加解密 6 /// <summary> 7 /// AES 解密 8 /// </summary> 9 /// <param name="toDecrypt"></param> 10 /// <returns></returns> 11 public static string AesDecrypt(string toDecrypt) { 12 byte[] keyArray = Encoding.UTF8.GetBytes("12345678901234567890123456789012"); 13 byte[] toEncryptArray = Convert.FromBase64String(toDecrypt); 14 15 RijndaelManaged rDel = new RijndaelManaged(); 16 rDel.Key = keyArray; 17 rDel.Mode = CipherMode.ECB; 18 rDel.Padding = PaddingMode.PKCS7; 19 20 ICryptoTransform cTransform = rDel.CreateDecryptor(); 21 byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length); 22 23 return Encoding.UTF8.GetString(resultArray); 24 } 25 26 /// <summary> 27 /// AES 加密 28 /// </summary> 29 /// <param name="toEncrypt"></param> 30 /// <returns></returns> 31 public static string AesEncrypt(string toEncrypt) { 32 byte[] keyArray = Encoding.UTF8.GetBytes("12345678901234567890123456789012"); 33 byte[] toEncryptArray = Encoding.UTF8.GetBytes(toEncrypt); 34 35 RijndaelManaged rDel = new RijndaelManaged(); 36 rDel.Key = keyArray; 37 rDel.Mode = CipherMode.ECB; 38 rDel.Padding = PaddingMode.PKCS7; 39 40 ICryptoTransform cTransform = rDel.CreateEncryptor(); 41 byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length); 42 43 return Convert.ToBase64String(resultArray, 0, resultArray.Length); 44 } 45 #endregion 46 }