using System.Security.Cryptography;
private static readonly byte[] _key = { 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 };
private static readonly byte[] _iv = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
public static void Main()
var encodedUpn = @"•šÅÜ•µ—•ƒùЇ Ûƒ•óÄ#ß[•I¤t.•ù.Ì••";
var input = "seshenoy@microsoft.com";
var t1 = System.Text.Encoding.Default.GetString(t);
var encodedByte = System.Text.Encoding.Default.GetBytes(t1);
Console.WriteLine(Decrypt(encodedByte));
var t2 = System.Text.Encoding.Default.GetBytes(encodedUpn);
Console.WriteLine(Decrypt(t2));
public static byte[] Encrypt(string plainText)
using (var aesAlg = Aes.Create())
var encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);
using (var msEncrypt = new MemoryStream())
using (var csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
using (var swEncrypt = new StreamWriter(csEncrypt))
swEncrypt.Write(plainText);
encrypted = msEncrypt.ToArray();
public static string Decrypt(byte[] cipherText)
using (var aesAlg = Aes.Create())
var decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
using (var msDecrypt = new MemoryStream(cipherText))
using (var csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
using (var srDecrypt = new StreamReader(csDecrypt))
plaintext = srDecrypt.ReadToEnd();