Your new method takes these parameters:

You work as the application developer at Domain.com.
You are developing a new method that must encrypt confidential data.
The method must use the Data Encryption Standard (DES) algorithm. Your new method takes these parameters:
1. A byte array, named message, that must be encrypted by applying the DES algorithm.
2. A key, named key, which will be used to encrypt the data.
3. The initialization vector, named iv.
Once the data is encrypted, it must be added to the MemoryStream object.
Choose the code segment which will encrypt the specified data and add it to the MemoryStream object.

You work as the application developer at Domain.com.
You are developing a new method that must encrypt confidential data.
The method must use the Data Encryption Standard (DES) algorithm. Your new method takes these parameters:
1. A byte array, named message, that must be encrypted by applying the DES algorithm.
2. A key, named key, which will be used to encrypt the data.
3. The initialization vector, named iv.
Once the data is encrypted, it must be added to the MemoryStream object.
Choose the code segment which will encrypt the specified data and add it to the MemoryStream object.

A.
DES des = new DESCryptoServiceProvider();
des.BlockSize = message.Length;
ICryptoTransform crypto = des.CreateEncryptor(key, iv);
MemoryStream cipherStream = new MemoryStream();
CryptoStream cryptoStream = new CryptoStream(cipherStream, crypto, CryptoStreamMode.Write);
cryptoStream.Write(message, 0, message.Length);

B.
DES des = new DESCryptoServiceProvider();
ICryptoTransform crypto = des.CreateDecryptor(key, iv);
MemoryStream cipherStream = new MemoryStream();
CryptoStream cryptoStream = new CryptoStream(cipherStream, crypto, CryptoStreamMode.Write);
cryptoStream.Write(message, 0, message.Length);

C.
DES des = new DESCryptoServiceProvider();
ICryptoTransform crypto = des.CreateEncryptor();
MemoryStream cipherStream = new MemoryStream();
CryptoStream cryptoStream = new CryptoStream(cipherStream, crypto, CryptoStreamMode.Write);
cryptoStream.Write(message, 0, message.Length);

D.
DES des = new DESCryptoServiceProvider();
ICryptoTransform crypto = des.CreateEncryptor(key, iv);
MemoryStream cipherStream = new MemoryStream();
CryptoStream cryptoStream = new CryptoStream(cipherStream, crypto, CryptoStreamMode.Write);
cryptoStream.Write(message, 0, message.Length);

Explanation:
Use the DesCryptoServiceProvider to create a new encryptor.Create a CryptoStream that encrypt directly to the MemoryStream and call the Write() method to perform the encryption.
A Uses a blocksize set to size of the entire message
B creates a decryptor instead of an encryptor.
C does not initialize the encryptor with the key and iv correctly.



Leave a Reply 1

Your email address will not be published. Required fields are marked *


mr_tienvu

mr_tienvu

Correct answer is D