0
0
Unityframework~10 mins

Data encryption basics in Unity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
ACreate
BCreateEncryptor
CGenerateKey
DGenerateIV
Attempts:
3 left
💡 Hint
Common Mistakes
Using CreateEncryptor() instead of Create()
Trying to generate key or IV directly without creating AES object
2fill in blank
medium

Complete 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'
AGenerateKey
BDispose
CGenerateIV
DCreateEncryptor
Attempts:
3 left
💡 Hint
Common Mistakes
Calling GenerateIV() instead of GenerateKey()
Calling CreateEncryptor() before generating key
3fill in blank
hard

Fix 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'
AGenerateKey
BCreateEncryptor
CGenerateIV
DCreateDecryptor
Attempts:
3 left
💡 Hint
Common Mistakes
Using CreateDecryptor instead of CreateEncryptor
Calling GenerateKey or GenerateIV instead of creating encryptor
4fill in blank
hard

Fill 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'
ACryptoStreamMode.Write
BCryptoStreamMode.Read
CWrite
DRead
Attempts:
3 left
💡 Hint
Common Mistakes
Using CryptoStreamMode.Read instead of Write
Calling Read() instead of Write() on CryptoStream
5fill in blank
hard

Fill 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'
ACreateDecryptor
BCryptoStreamMode.Read
CRead
DCreateEncryptor
Attempts:
3 left
💡 Hint
Common Mistakes
Using CreateEncryptor instead of CreateDecryptor
Using CryptoStreamMode.Write instead of Read
Calling Write() instead of Read() on CryptoStream