Complete the code to create a new AES encryption object.
using System.Security.Cryptography;
Aes aes = Aes.[1]();The Aes.Create() method creates a new AES encryption object.
Complete the code to generate a random encryption key.
using System.Security.Cryptography;
Aes aes = Aes.Create();
aes.[1]();The GenerateKey() method creates a new random key for encryption.
Fix the error in the code to create an encryptor with the AES key and IV.
using System.Security.Cryptography;
Aes aes = Aes.Create();
aes.GenerateKey();
aes.GenerateIV();
ICryptoTransform encryptor = aes.[1](aes.Key, aes.IV);The CreateEncryptor(key, iv) method creates an encryptor using the AES key and IV.
Fill both blanks to encrypt data using the encryptor and a CryptoStream.
using System.IO;
using System.Security.Cryptography;
byte[] data = new byte[] {1, 2, 3};
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, encryptor, [1]);
cs.[2](data, 0, data.Length);To encrypt data, use CryptoStreamMode.Write and call Write() on the CryptoStream.
Fill all three blanks to decrypt data using a decryptor and CryptoStream.
using System.IO;
using System.Security.Cryptography;
byte[] encryptedData = new byte[] {5, 6, 7};
MemoryStream ms = new MemoryStream(encryptedData);
ICryptoTransform decryptor = aes.[1](aes.Key, aes.IV);
CryptoStream cs = new CryptoStream(ms, decryptor, [2]);
byte[] decrypted = new byte[encryptedData.Length];
cs.[3](decrypted, 0, decrypted.Length);To decrypt data, create a decryptor with CreateDecryptor, use CryptoStreamMode.Read, and call Read() on the CryptoStream.
