Vous êtes sur la page 1sur 9

Cryptography

Demo Script
Cryptography............................................................................................................................................................................................................... 1
Demo Script................................................................................................................................................................................................................. 1
Demo Setup Instructions.............................................................................................................................................................................................. 2
Demo 0: Symmetric Encryption.................................................................................................................................................................................... 3
Demo 1: Asymmetric Encryption.................................................................................................................................................................................. 4
Demo 2: Hashing......................................................................................................................................................................................................... 5
Demo 3: Digital Signatures.......................................................................................................................................................................................... 7
Demo Reset Instructions.............................................................................................................................................................................................. 8
Demo Setup Instructions
The following steps must be completed before the demos can be run.
Setting up the demo PC
1. Install Visual C# 2005 or Visual Studio 2005.
Demo 0: Symmetric Encryption
In this demo well take a look at symmetric, or shared key, encryption using the Rijndael algorithm.
Steps Example
1. Open Microsoft.TeachingObjects.Cryptography.sln in Visual C# 2005/Visual Studio 2005.

2. Select Debug | Start Debugging to run the application in debug mode. When the application loads,
the generated key for the Rijndael algorithm will be displayed. Note that it is a short key (256 bits).

3. On the Symmetric tab, enter Hello World into the Input Data text field and press Encrypt.

4. The Rijndael (AES) text field will display the base-64 encoded version of the encrypted value. Note
that the encrypted data is roughly the same length as the source data (after you account for the
base-64 encoding of the cipher text).
5. Press the Decrypt button to decrypt the data back into plaintext. Note that the same key is being
used for both the encryption and the decryption.

6. Keep the application open for the next demo.

Demo 1: Asymmetric Encryption


In this demo well take a look at asymmetric, or public key, encryption using the RSA algorithm.
Steps Example
1. In the demo application, switch to the Asymmetric tab. If the application isnt running, select Debug
| Start Debugging to run it. Note that the tab displays key information as XML. XML is often used to
store RSA key information due to its complexity and many fields. This key data includes both public
and private key data, although the key itself is only 1024 bits.

2. Enter Hello World into the Input Data text field and press Encrypt.
3. The RSA text field will display the base-64 encoded version of the encrypted value. Note that the
encrypted data takes significantly more space than the symmetric encryption of the same data using
Rijndael did. This is partly due to the nature of asymmetric algorithms, which always produce the
same cipher text length.

4. Press the Decrypt button to decrypt the data back into plaintext. Note that the key being used for
both decryption is different than the one being used for encryption.

5. RSA supports encryption of up to 117 bytes. Enter at least 118 characters into the Input Data text
field and press Enter. Note that this application has been developed to catch this exception since it
is known that asymmetric encryption has size limitations.

6. Keep the application open for the next demo.

Demo 2: Hashing
In this demo well take a look at hashing using the SHA-256 algorithm.
Steps Example
1. In the demo application, switch to the Hash tab. If the application isnt running, select Debug | Start
Debugging to run it.

2. Enter Hello World into the Input Data text field and press Encrypt.

3. Press the Hash button to hash the input data. The 256 bit value will be displayed in base-64 in the
SHA-256 text box.

4. Change the last letter of the input text from d to e so that it reads Hello Worle. Press the Hash
button to hash the new input. Note how the new hash is completely different from the old hash. This
is very important because is indicates that a single changed bit in the source data has a significant
impact on the output hash, making collisions in similar data virtually impossible.

5. Repeat the hash process with more data, including very long text. Note that the hash size always
remains the same and that the values are always unique.

6. Keep the application open for the next demo.


Demo 3: Digital Signatures
In this demo well take a look at digital signatures using the RSA algorithm.
Steps Example
1. In the demo application, switch to the Sign tab. If the application isnt running, select Debug | Start
Debugging to run it.

2. Enter Hello World into the Input Data text field and press Sign.

3. The RSA Signature text field will display the base-64 encoded version of the digital signature. Note
that the private key was used to generate this signature.

4. Press the Verify button to verify that the original data matches the digital signature. Note that the
public key was used to verify the signature.
5. Change the first character of the RSA Signature to something different. Press the Verify button to
see if the signature is still valid. It shouldnt be, which indicates that the signature or source data was
tampered with.

6. Press the Sign button to regenerate the signature. This time, change the Input Data H to I so that
the input text reads Iello World. Press Verify to see if the signature is still valid. It shouldnt be,
which indicates that the signature or source data was tampered with.

7. Close the application.

8. Close Visual C# 2005/Visual Studio 2005.


Demo Reset Instructions
These demos do not require any special steps to rest their state.