Lab 2 - Secret Key Encryption Lab
Lab 2 - Secret Key Encryption Lab
Table of Contents
Overview......................................................................................................................................2
Task 1: Installing OpenSSL package..............................................................................................2
Task 2: OpenSSL for encryption and decryption of images and text..............................................2
Task 2a: Encryption using different ciphers and modes..........................................................................2
Task 2b: Encryption Mode ECB vs CBC...................................................................................................3
Task 2c: Padding...................................................................................................................................4
Task 2d: Error propagation – corrupted Ciphertext................................................................................5
Task 2e: Initialization Vector.................................................................................................................6
Task 3: Programming Using the crypto Library.............................................................................6
Submission...................................................................................................................................8
1
BNM Institute of Technology Department of CSE
Cryptography
Lab 2: Secret Key Encryption Lab
Overview
The learning objective of this lab is for students to get familiar with the concepts in the
secret-key encryption and some common attacks on encryption. From this lab, students will
gain a first-hand experience on encryption algorithms, encryption modes, paddings, and
initial vector (IV). Moreover, students will be able to use tools and write programs to
encrypt/decrypt messages. Many common mistakes have been made by developers in using
the encryption algorithms and modes. These mistakes weaken the strength of the
encryption, and eventually lead to vulnerabilities. This lab exposes students to some of
these mistakes, and ask students to launch attacks to exploit those vulnerabilities.
This lab covers the following topics:
Lab Tasks
Task 1: Installing OpenSSL package
Step 1: install OpenSSL using following commands
sudo apt-get install openssl
or
sudo yum install openssl
Commands:
$touch plain.txt
$gedit plain.txt
$cat plain.txt
2
BNM Institute of Technology Department of CSE
Cryptography
Lab 2: Secret Key Encryption Lab
Command:
$openssl enc -aes-128-cbc -e -in plain.txt -out cipher1.bin -k
00112233445566778899aabbccddeeff -iv 0102030405060708090a0b0c0e0f
3
BNM Institute of Technology Department of CSE
Cryptography
Lab 2: Secret Key Encryption Lab
Step 2:
Once the two encrypted files are generated appropriate headers need to be added so that
image viewing s/w recognise the image
Step 3:
View the encrypted images and draw conclusion
$eog filename
Step 1: create 3 files of size 5,10,15 bytes respectively (create text file)
Commands:
$ echo -n “12345”>f1.txt
$ echo -n “1234567890”>f2.txt
$ echo -n “1234567890abcdef”>f3.txt
$ ls – l f*.txt
4
BNM Institute of Technology Department of CSE
Cryptography
Lab 2: Secret Key Encryption Lab
$ xxd p1.txt
$ xxd p2.txt
$ xxd p3.txt
Repeat this task with ecb and other modes for more marks.
Step 2: Encrypt the file using AES-128 cipher and manually corrupt one bit
Commands:
$openssl enc -aes-128-ecb -e -in plain.txt -out cipher1.bin -k
00112233445566778899aabbccddeeff -iv 0102030405060708090a0b0c0e0f
5
BNM Institute of Technology Department of CSE
Cryptography
Lab 2: Secret Key Encryption Lab
$ ghex cipher.bin
Use hex editor ghex to change one bit.
Commands:
6
BNM Institute of Technology Department of CSE
Cryptography
Lab 2: Secret Key Encryption Lab
7
BNM Institute of Technology Department of CSE
Cryptography
Lab 2: Secret Key Encryption Lab
Submission
You need to submit a detailed lab report to describe what you have done and what you have
observed, including screenshots and code snippets. You also need to provide explanation to the
observations that are interesting or surprising. You are encouraged to pursue further investigation,
beyond what is required by the lab description. Please submit in word or PDF format only.
8
BNM Institute of Technology Department of CSE