Information Security and Cryptography
CS302
Lab Assignment: 7
Name : Hetvi Modi
Roll no : U22CS074
This assignment is about exploring the OpenSSL library. Follow the below
instructions:
• Install OpenSSL Win64 OpenSSL v3.2.1 to your computer
using the following site:
https://slproweb.com/products/Win32OpenSSL.html • Run the
.exe file and install OpenSSL in the system. Open the command
prompt (cmd) and redirect the path to the bin folder.
Task 1: RSA Encryption and Decryption
Perform encryption and decryption of a file using the RSA public-key
encryption technique with OpenSSL commands.
Steps:
1. Generate a public and private key pair using
the following OpenSSL commands:
openssl genrsa -out private.key 512 openssl
rsa -in private.key -pubout -out public.key
2. Encrypt the file using the public key: openssl
rsautl -encrypt -inkey public.key -pubin -in file.txt -
out file.enc
3. Decrypt the file using the private key:
openssl rsautl -decrypt -inkey private.key -in
file.enc -out file.dec
Note: In OpenSSL 3.0 and later, rsautl has been deprecated, and you should
use pkeyutl instead.
Task 2: Diffie-Hellman Key Exchange
Use OpenSSL to perform a Diffie-Hellman (DH) key exchange to securely
generate a shared secret between two parties.
Steps:
1. Generate DH parameters:
openssl dhparam -out dhparam.pem 2048
2. Generate private and public keys for Party A:
openssl genpkey -paramfile dhparam.pem -out
privateA.pem openssl pkey -in privateA.pem -pubout -out
publicA.pem
3. Generate private and public keys for Party B:
openssl genpkey -paramfile dhparam.pem -out
privateB.pem openssl pkey -in privateB.pem -pubout -
out publicB.pem 4. Derive shared secret for Party A
(using Party B’s public key):
openssl pkeyutl -derive -inkey privateA.pem -peerkey
publicB.pem -out shared_secret_A.bin
5. Derive shared secret for Party B (using Party A’s public key):
openssl pkeyutl -derive -inkey privateB.pem -peerkey
publicA.pem -out shared_secret_B.bin
6. Verify that both shared secrets are the same:
Compare the contents of shared_secret_A.bin and shared_secret_B.bin.
Output :