NIS 17 Cryptolab
NIS 17 Cryptolab
JUNE, 2023
Lab – Encrypting and Decrypting Data Using OpenSSL
Objectives
Part 1: Encrypting Messages with OpenSSL
Part 2: Decrypting Messages with OpenSSL
Background / Scenario
OpenSSL is an open-source project that provides a robust, commercial-grade, and full-
featured toolkit for the Transport Layer Security (TLS) and Secure Sockets Layer (SSL)
protocols. It is also a general-purpose cryptography library. In this lab, you will use OpenSSL
to encrypt and decrypt text messages.
Note: While OpenSSL is the de facto cryptography library today, the use presented in this lab
is NOT recommended for robust protection. Below are two security problems with this lab:
1. The method described in this lab uses a weak key derivation function. The ONLY
security is introduced by a very strong password.
2. The method described in this lab does not guarantee the integrity of the text file.
This lab should be used for instructional purposes only. The methods presented here should
NOT be used to secure truly sensitive data.
Required Resources
Kali Linux virtual machine
Instructions
Part 1: Encrypting Messages with OpenSSL
OpenSSL can be used as a standalone tool for encryption. While many encryption algorithms
can be used, this lab focuses on AES. To use AES to encrypt a text file directly from the
command line using OpenSSL, follow the steps below:
Step 1: Encrypting a Text File
a. Log into your kali Linux VM.
b. Open a terminal window.
c. Make a directory in Desktop/projects and put the text file to be encrypted in that
directory create a file called letter_to_grandma.txt and copy the following text into it:
Hi Grandma,
I am writing this letter to thank you for the chocolate chip cookies you sent me. I got them
this morning and I have already eaten half of the box! They are absolutely delicious!
I wish you all the best. Love,
Your cookie-eater grandchild.
Screenshot:
f. When the process is finished, use the appropriate command again to display the contents
of the grandma.enc file.
Screenshot:
Did the contents of the grandma.enc file display correctly? What does it look like? Explain.
Ans: From the above diagram, the message didn’t display because it has been encrypted
with a key or password. The message will be displayed when the right key or password has
been give out to the receiver.
g. To make the file readable, run the OpenSSL command again, but this time add the -
a option before the -in but change the -out file name to grandma1.enc. The -a option tells
OpenSSL to encode the encrypted message using a different encoding method of Base64
before storing the results in a file.
Note: Base64 is a group of similar binary-to-text encoding schemes used to represent binary
data in an ASCII string format.
Screenshot:
h. Once again, use the appropriate command to display the contents of the, now re-
generated, grandma.enc file:
Note: The contents of grandma.enc and grandma1.enc will vary.
Screenshot:
b. OpenSSL will ask for the password used to encrypt the file. Enter the same password
again.
Screenshot:
c. When OpenSSL finishes decrypting the grandma.enc and grandma1.enc file, it saves the
decrypted message in a text file. Use the cat display the contents:
Screenshot: