static void Main(string[] args) { Protection protect = new Protection(); try { using (AesManaged aes = new AesManaged()) { Console.Write("please enter some text you want to Encrypt:"); string text = Convert.ToString(Console.ReadLine()); // encrypt the string to an array byte[] encrypt = protect.encode(text, aes.Key, aes.IV); string eText = String.Empty; foreach (var b in encrypt) { eText += b.ToString() + ", "; } Console.WriteLine(Environment.NewLine + $"Encrypted text: {eText}"); Console.WriteLine("Please hit enter to Continue"); Console.ReadLine(); // Now decrypt the bytes to string string decrypted = protect.Decrypt(encrypt, aes.Key, aes.IV); Console.WriteLine(Environment.NewLine + $"Decrypted text : {decrypted}"); } } catch (Exception e) { Console.WriteLine(Environment.NewLine + $"Error:{e.Message}"); } Console.ReadLine(); }