using System.Security.Cryptography;
public static void Main()
var txt="someone[a]somedomain.com";
var cypher = Encrypt(txt, key:"EJlzmwq090f7Ckcoe1zuS1EscP2hpTcs8l/ZT69Uj5U=", salt:"Neg4LxF01KcSZ1Thw6jA3Q==");
Console.WriteLine(string.Format("from {0} to {1} characters",txt.Length,cypher.Length));
txt="someone.compleately.different[a]somedomain.com";
cypher = Encrypt(txt, key:"EJlzmwq090f7Ckcoe1zuS1EscP2hpTcs8l/ZT69Uj5U=", salt:"Neg4LxF01KcSZ1Thw6jA3Q==");
Console.WriteLine(string.Format("from {0} to {1} characters",txt.Length,cypher.Length));
protected static string Encrypt(string text, string key, string salt)
if (string.IsNullOrEmpty(text)) return string.Empty;
return EncryptStringToBytes_Aes(text
, Convert.FromBase64String(key)
, Convert.FromBase64String(salt)
static string EncryptStringToBytes_Aes(string plainText, byte[] Key, byte[] IV)
if (plainText == null || plainText.Length <= 0)
throw new ArgumentNullException("plainText");
if (Key == null || Key.Length <= 0)
throw new ArgumentNullException("Key");
if (IV == null || IV.Length <= 0)
throw new ArgumentNullException("IV");
using (AesCryptoServiceProvider aesAlg = new AesCryptoServiceProvider())
aesAlg.Padding = PaddingMode.ISO10126;
ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);
using (MemoryStream msEncrypt = new MemoryStream())
CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write);
using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
swEncrypt.Write(plainText);
encrypted = msEncrypt.ToArray();
return Convert.ToBase64String(encrypted);