using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; namespace ApplicationAvalonia.Utilities { public static class EncryptionClass { public static byte[] Encrypt(string simpleText, byte[] key, byte[] iv) { byte[] cipheredText; using (Aes aes = Aes.Create()) { ICryptoTransform encryptor = aes.CreateEncryptor(key, iv); using (MemoryStream memoryStream = new MemoryStream()) { using (CryptoStream cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write)) { using (StreamWriter streamWriter = new StreamWriter(cryptoStream)) { streamWriter.Write(simpleText); } cipheredText = memoryStream.ToArray(); } } } return cipheredText; } public static string Decrypt(byte[] cipheretext, byte[] key, byte[] iv) { string simpleText = String.Empty; using (Aes aes = Aes.Create()) { ICryptoTransform decryptor = aes.CreateDecryptor(key, iv); using (MemoryStream memoryStream = new MemoryStream(cipheretext)) { using (CryptoStream cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read)) { using (StreamReader streamReader = new StreamReader(cryptoStream)) { simpleText = streamReader.ReadToEnd(); } } } } return simpleText; } } }