Lab 8
Lab 8
Rich Macfarlane
Aim: The aim of these labs and exercises is to understand the concepts and use, of Symmetric
(Private-Key) Encryption – which is typically used to protect data confidentiallity, and Hash
Signatures – which can be used to protect data integrity, authentication, and confidentiality.
Time to complete:
4 hours (2 supervised hours in the lab, and 2 additional hours, unsupervised).
Activities:
Complete Lab 8: Symmetric Encryption & Hash Signatures.
.pdf from WebCT or http://www.dcs.napier.ac.uk/~cs342/CSN11102/Lab8.pdf
(Use Unit 3 – Encryption for reference while completing the lab)
The End Of Unit Test questions for the Authentication chapter at:
http://www.asecuritysite.com/security/tests/tests?sortBy=sfc04
Learning activities:
At the end of these activities, you should understand:
Understand some of the basic methods of Symmetric (private-key) Encryption for
confidentiality.
Understand the basic methods used in Hash Signatures.
Understand the conversion of binary to the human readable Base-64 and Hexadecimal
encoding formats.
References:
Course Handbook - Unit 3 Encryption.
8.1 Details
Aim: To provide a foundation in data encryption using symmetric encryption algorithms, and hash
signatures generation algorithms.
8.2 Activities
Open the zip file, and extract the EncryptionLab folder to the Desktop using the Extract All
button.
From the Windows Desktop, open the C#.NET solution by double clicking the .sln file. Choose
the C# Development Settings if requested, and convert the code to the latest version of
C#.NET if required.
The solution should contain two applications. A windows console application
encryptionConsole and a Windows GUI Form application encryptionForm. The
encryptionConsole application should be set as the StartUp Application (highlighted in bold).
The .NET framework provides a number of cryptography classes. To help simplify using these
classes, we use code wrapper class XCryptEngine (pdwolf, 2003) which also implements
the BlowFish and TwoFish algorithms (not provided natively in C#).
// Hash Algorimths.
// xe.InitializeEngine(XCryptEngine.AlgorithmType.MD5);
// xe.InitializeEngine(XCryptEngine.AlgorithmType.RC2);
// xe.InitializeEngine(XCryptEngine.AlgorithmType.Rijndael);
// xe.InitializeEngine(XCryptEngine.AlgorithmType.SHA);
// xe.InitializeEngine(XCryptEngine.AlgorithmType.SHA256);
Try some of the other Symmetric Encryption algorithms, and then some of the Hash
algorithms. Try Hashing and encrypting your name.
Questions
Q: What two fundamental difference between the two algorithms, does the output show?
Q: Which additional item, is needed by all encryption algorithms, but not hash algorithms?
(See Encryption Unit in the Module Handbook – Sections 3.4, 3.11 for reference)
Hash Algorithms such as MD5 and SHA-1, as well as Symmetric Encryption Algorithms such
as DES, 3DES. Symmetric Encryption Algorithms use a single secret key, to both encrypt and
decrypt a message, where hash algorithms only encrypt and do not need a key.
Hash Algorithms or Functions can be used in a wide variety of ways. For example, they can be used
for encryption to provide confidentiality such as with Password encryption, they can provide
integrity of messages, and are used extensively in digital forensics for file identification and evidence
integrity.
In the example below Bob creates a Hash Signature (or Digest) from some Plain Text, using a one
way Hash Algorithm. The generated signature cannot be unencrypted back into the Plain Text, so if
this was Bobs password Eve could not decrypt it.
Bob
fa1bfa14fa13fa12fa10fa1ffa14fa12
PlainText Hash Hash
Signature
Hash Algorithm used
to produce a Hash
Signature (or
Eve
Eve can capture but
Fingerprint) can’t decrypt one
(MD5, SHA) way Hash.
Use the encryptionForm application, Hash Signatures tab, to compare the outputs from
the Hash Algorithms: MD5 (128-bit), SHA-1 (160-bit), SHA-256 (256-bit), SHA-384 (384-bit),
SHA-512 (512-bit) and complete the following table (only the first few characters of each hash
signature). The interface is shown below.
Note: To use the encryptionForm application, in the Solution Explorer, right click over
encryptionForm and choose SetAsStartUp Project.
Questions
Q: Can you fill out some of the following table for the two hash algorithms? (maybe just the first few
char’s)
password
Password
Questions
Q: What do you notice about the output from the hash algorithms, if you change only a single letter
even in a very long string?
Q: What do you notice about the output from the hash algorithms, regarding the length of signatures
for any single algorithm?
Q: Complete the table below for the number of characters in the Hash Signatures output and the
length of the binary output, produced by each different Hash Algorithm:
Number of Bits:
Questions
Q: What is the encoding format being used to display the Hash Signatures in the
encryptionForm?
Q: What relationship does the encoding type have with the length of the signature in binary?
Commonly we see Hash Signatures displayed in HEX encoding. To see the same MD5
signature displayed in HEX, we can add some code to the HEX Hash Sig’s button:
Double click on the Create HEX Hash Signatures button, and add the following code to the
button click event:
xe.InitializeEngine(XCryptEngine.AlgorithmType.MD5);
string encText = Base64ToHex(xe.Encrypt(tbTextToHash.Text));
tbMD5Hash.Text = encText + " - Len: " + encText.Length;
And, add the following method (somewhere after the method main so the button click event
can call it):
Q: What are the Hex and Base-64 hash signatures for “hack”?
Base-64 Signature Hex Signature
Double click on the Create HEX Hash Signatures button, and add similar code for the other hash
algorithms, with code such as the following.
xe.InitializeEngine(XCryptEngine.AlgorithmType.SHA);
string encText = Base64ToHex(xe.Encrypt(tbTextToHash.Text));
tbSHAHash.Text = encText + " - Len: " + encText.Length;
xe.InitializeEngine(XCryptEngine.AlgorithmType.SHA256);
string encText = Base64ToHex(xe.Encrypt(tbTextToHash.Text));
tbSHA256Hash.Text = encText + " - Len: " + encText.Length;
Questions
Q: Complete the table below for the number of characters in the Hash Signatures output in hexfor
each different Hash Algorithm:
Number of Bits:
Questions
Q: Why are the Hex and Base-64 hash signatures different lengths?
Bob
Alice
Cipher Cipher
PlainText PlainText
CipherText CipherText
3. Decrypt using
2. Encrypt using same Symmetric
Symmetric Algorithm Algorithm
(DES, RC4, AES) (DES, RC4, AES)
Eve
Eve can capture
communications, but
can’t read contents
Run the Form Application and switch to the Symmetric Encryption tab, as shown below.
Questions
Q: If you change the decryption key, does the program decrypt correctly?
Q: Reset the keys to the same value. If you now encrypt some text, then change the encrypted text,
does the program decrypt correctly?
Compare the Symmetric Algorithms: DES, 3DES, Blowfish, RC2 and complete the following
table (only the first few characters).
Text DES 3DES Blowfish RC2
A
Password
Password
Q: What are the fundamental differences between Ciphertext generated by Hash Algorithms and the
Ciphertext generated by the Symmetric Algorithms?
Q: What is the main problem with symmetric encryption, in particular concerning Bob and Alice
having the same secret key?
using System;
using System.Collections.Generic;
using System.Text;
using XCrypt;
namespace bruteForceConsole
{
class Program
{
static void Main(string[] args)
{
// Create Cryptography Object.
XCryptEngine xe = new XCryptEngine();
Modify it so that it can brute force a 2-character encryption key, and then a 3 and then 4
character one.
(Hint: Nested for loops or a recursive function might help)
Q: Measure the approximate time it takes for the different key length searches:
Perform 5 test runs for each key length with randomly selected keys, measuring the approximate
time taken for each run.
2 characters:
3 characters:
4 characters: