using System.Text;
using System.Security.Cryptography;
/// <summary>
/// AES encode.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static string AesEncode(string value)
{
using (Aes aes = Aes.Create())
{
using (ICryptoTransform encryptor = aes.CreateEncryptor(aesKey, aesKey))
{
byte[] buffer = Encoding.UTF8.GetBytes(value);
buffer = encryptor.TransformFinalBlock(buffer, 0, buffer.Length);
return Convert.ToBase64String(buffer);
}
}
}
/// <summary>
/// AES decode.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static string AesDecode(string value)
{
using (Aes aes = Aes.Create())
{
using (ICryptoTransform decryptor = aes.CreateDecryptor(aesKey, aesKey))
{
byte[] buffer = Convert.FromBase64String(value);
buffer = decryptor.TransformFinalBlock(buffer, 0, buffer.Length);
return Encoding.UTF8.GetString(buffer);
}
}
}