1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
public static class Aes { private static readonly byte[] Key = Convert.FromBase64String("rAO85BOVE3bIh2KEjbFlQ7uVYjzD5UdHGPET2YnDxbM=");
private static readonly byte[] IV = Convert.FromBase64String("fsUfF+aIEeTsp9SfmMvHkA==");
public static string Encrypt(string plainText, Encoding encoding = null) { encoding = encoding ?? Encoding.UTF8; using (var rij = new RijndaelManaged { Key = Key, IV = IV, Mode = CipherMode.CBC, Padding = PaddingMode.PKCS7 }) { var plainBytes = encoding.GetBytes(plainText); return Convert.ToBase64String(rij.CreateEncryptor().TransformFinalBlock(plainBytes, 0, plainBytes.Length)); } }
public static string Decrypt(string cipherText, Encoding encoding = null) { encoding = encoding ?? Encoding.UTF8; using (var rij = new RijndaelManaged { Key = Key, IV = IV, Mode = CipherMode.CBC, Padding = PaddingMode.PKCS7 }) { var cipherBytes = Convert.FromBase64String(cipherText); return encoding.GetString(rij.CreateDecryptor().TransformFinalBlock(cipherBytes, 0, cipherBytes.Length)); } } }
|