using System.Security.Cryptography;
public class AesEncryption
private static string encryptionKey = "PZYvdF18G3OowTKueNwLkjc3iPCQnQuv";
public static string EncryptAES(string plaintext)
byte[] byteMsg = Encoding.UTF8.GetBytes(plaintext);
using (Aes aesAlg = Aes.Create())
aesAlg.Key = Encoding.UTF8.GetBytes(encryptionKey);
aesAlg.Mode = CipherMode.CFB;
byte[] iv = new byte[aesAlg.BlockSize / 8];
using (var rng = new RNGCryptoServiceProvider())
using (ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, iv))
using (MemoryStream msEncrypt = new MemoryStream())
msEncrypt.Write(iv, 0, iv.Length);
using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
swEncrypt.Write(plaintext);
return Convert.ToBase64String(msEncrypt.ToArray());
public static void Main()
string plaintext = "Hello, world!";
string encryptedText = EncryptAES(plaintext);
Console.WriteLine("Encrypted Text: " + encryptedText);