using System.Security.Cryptography;
private static byte[] cryptkey = Encoding.ASCII.GetBytes("97e638565b8244128e10077c8baba66e");
private static byte[] initVector = Encoding.ASCII.GetBytes("79ff9b5616b427da");
public static void Main()
var testo1 = "402373020729280368505/20";
Console.WriteLine("Crittare '{0}' produce: {1}", testo1, CryptAES(testo1));
public static string DecryptAES(string cipherData)
using (var rijndaelManaged =
new RijndaelManaged { Key = cryptkey, IV = initVector, Mode = CipherMode.CBC })
using (var memoryStream =
new MemoryStream(Convert.FromBase64String(cipherData)))
using (var cryptoStream =
new CryptoStream(memoryStream,
rijndaelManaged.CreateDecryptor(cryptkey, initVector),
return new StreamReader(cryptoStream).ReadToEnd();
catch (CryptographicException e)
Console.WriteLine("A Cryptographic error occurred: {0}", e.Message);
public static string CryptAES(string textToCrypt)
using (var rijndaelManaged =
new RijndaelManaged { Key = cryptkey, IV = initVector, Mode = CipherMode.CBC })
using (var memoryStream = new MemoryStream())
using (var cryptoStream =
new CryptoStream(memoryStream,
rijndaelManaged.CreateEncryptor(cryptkey, initVector),
using (var ws = new StreamWriter(cryptoStream))
return Convert.ToBase64String(memoryStream.ToArray());
catch (CryptographicException e)
Console.WriteLine("A Cryptographic error occurred: {0}", e.Message);