CONTENTS

Cryptography Using .NET: Exercises

Exercises.  From the previous sections, you learned about encryption, hashing, and digital signatures for use with C# and the .NET Framework.  In this section you will be presented with a number of exercises requiring you to use the knowledge you learned from the previous sections along with a number of questions. 

If you are submitting your work include your name in the header of each program for problem 1 - 7.  Each program must be named according to its associated problem, e.g., Problem1.cs. . . Problem7.cs.  Zip all the files into one file and upload it onto the class FTP server.  You must include printouts of each program and answers to each question. 

Problem 1.  Encrypt a plaintext with the following options: -AES-CBC mode with PKCS#7 padding mode -128-bit key size and block size.

Key = { 0xFC, 0x02, 0xC6, 0x04,
              0x05, 0x06, 0x07, 0x08,
              0x27, 0x10, 0x83, 0x12,
              0x3B, 0x14, 0x15, 0xAF }

IV = { 0x99, 0x5C, 0x8F, 0x04,
           0x05, 0x06, 0x07, 0x08,
           0x09, 0x8E, 0x11, 0x12,
           0x13, 0x14, 0x15, 0x99 }

Plaintext: Identification and Two-factor Authentication

What is the Base64-encoded ciphertext? _________________________________________________

Consider the Convert.ToBase64String(byte[] array) and Convert.FromBase64String(string s) methods.

Problem 2.  Write a decryption program to verify your answer in Problem 1. 

Hints:

  • You can add an additional decryption method inside the CryptoClass class.
  • Create a byte array to save the decrypted message, such as byte[] array1 = new byte[x_cipher_rx.Length];,where x_cipher_rx is the byte array obtained after using FromBase64String to decode the received Base64-encoded ciphertext.
  • You need to create an instance of MemoryStream initialized with the byte array x_cipher_rx (we no longer use the default constructor of MemoryStream here).
  • Use the CreateDecryptormethod similar to the CreateEncryptor method in the encryption example, and also use Readinstead of Write here.

Problem 3.  Given ciphertext and plaintext use the information provided in Problem 1 except for the key to find the last missing three bytes of the key. 

Base64-encoded ciphertext: T6+b7B9/iXa5ennZ+dpG/mmCURaBiTthLHitnmZN5vY=
Plaintext:  Central Intelligence Agency
Partial key (first 13 bytes): Partial_Key = { 0xFC, 0x02, 0xC6, 0x04,
                                                                            0x05, 0x06, 0x07, 0x08,
                                                                            0x27, 0x10, 0x83, 0x12,
                                                                            0x3B }

What are the last three bytes of the key in Hexadecimal form? _________________________________________________

Problem 4.  Given a message you must compute the hash.

Message: Programming .NET Security Part I

What is the hash code?     _________________________________________________
Comment on the results. _________________________________________________

Change the message to: Programming .NET Security Part V

What is the hash code?      _________________________________________________
Comment on the results.  _________________________________________________

Problem 5: Keyed Hashing Algorithm.  Compute the HMACSHA1 hash code using the given message. 

Message: Martin Luther King, Jr. Key: I Have a Dream

What is the output hash code? _________________________________________________

Problem 6: DSA Digital Signature.  Write a DSA digital signature program to show the following processes.

1. Alice signs the message: Digital Signature and Electronic Authentication Law
2. She exports her public parameters using the ExportParameters method.
3. Bob receives the signature and imports the public parameters
4. Bob verifies the signature.

The output printout must show both the signature and the byte arrays of the random number P and Q, which are Alice’s public parameters.

Problem 7: RSA Digital Signature. Write a RSA (with SHA-1 hashing algorithm) digital signature program to show the following processes:

1. Alice signs the message: Public-Key Cryptography Standards (PKCS)
2. Do the same as in Problem 6, but use the XML parameter exporting/importing instead.

The output must show both the signature and its associated XML string of public keys. You will see the Modulus and Exponent values inside this XML string.