Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new AES encryption object.
Unity
using System.Security.Cryptography;
Aes aes = Aes.[1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using CreateEncryptor() instead of Create()
Trying to generate key or IV directly without creating AES object
✗ Incorrect
The Aes.Create() method creates a new AES encryption object.
2fill in blank
mediumComplete the code to generate a random encryption key.
Unity
using System.Security.Cryptography;
Aes aes = Aes.Create();
aes.[1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling GenerateIV() instead of GenerateKey()
Calling CreateEncryptor() before generating key
✗ Incorrect
The GenerateKey() method creates a new random key for encryption.
3fill in blank
hardFix the error in the code to create an encryptor with the AES key and IV.
Unity
using System.Security.Cryptography;
Aes aes = Aes.Create();
aes.GenerateKey();
aes.GenerateIV();
ICryptoTransform encryptor = aes.[1](aes.Key, aes.IV); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using CreateDecryptor instead of CreateEncryptor
Calling GenerateKey or GenerateIV instead of creating encryptor
✗ Incorrect
The CreateEncryptor(key, iv) method creates an encryptor using the AES key and IV.
4fill in blank
hardFill both blanks to encrypt data using the encryptor and a CryptoStream.
Unity
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); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using CryptoStreamMode.Read instead of Write
Calling Read() instead of Write() on CryptoStream
✗ Incorrect
To encrypt data, use CryptoStreamMode.Write and call Write() on the CryptoStream.
5fill in blank
hardFill all three blanks to decrypt data using a decryptor and CryptoStream.
Unity
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); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using CreateEncryptor instead of CreateDecryptor
Using CryptoStreamMode.Write instead of Read
Calling Write() instead of Read() on CryptoStream
✗ Incorrect
To decrypt data, create a decryptor with CreateDecryptor, use CryptoStreamMode.Read, and call Read() on the CryptoStream.