Lab 07 β Encryption in Practice with OpenSSL¶
Course: SCIA-120 Β· Introduction to Secure Computing
Topic: Cryptography β Symmetric & Asymmetric Encryption
Difficulty: ββ BeginnerβIntermediate
Estimated Time: 45β60 minutes
Related Reading: Chapter 6 β Cryptography Fundamentals
Overview¶
Cryptography is the backbone of modern information security. In this lab you will use OpenSSL β the industry-standard cryptography toolkit β entirely inside a Docker container to generate encryption keys, encrypt and decrypt files with both symmetric (AES) and asymmetric (RSA) encryption, and inspect a real TLS certificate. By the end, you will understand how encryption actually works at a practical level.
Learning Objectives¶
- Encrypt and decrypt a file using AES symmetric encryption.
- Generate an RSA public/private key pair.
- Encrypt data with a public key and decrypt with a private key.
- Understand when to use symmetric vs. asymmetric encryption.
- Inspect a real TLS certificate and identify its components.
Prerequisites¶
- Docker Desktop installed and running.
Part 1 β Symmetric Encryption with AES¶
Symmetric encryption uses the same key to encrypt and decrypt. It is fast and used for bulk data encryption.
Step 1.1 β Start an OpenSSL Container¶
Install OpenSSL:
Step 1.2 β Create a Sensitive File¶
echo "Patient Record: John Smith, DOB: 1985-03-14, Diagnosis: Hypertension" > patient_record.txt
cat patient_record.txt
Step 1.3 β Encrypt with AES-256-CBC¶
You will be prompted for a password β use SecureKey123. Enter it twice.
The encrypted file is unreadable binary data (gibberish characters).
πΈ Screenshot checkpoint: Take a screenshot showing the encrypted file content (unreadable ciphertext).
Step 1.4 β Decrypt the File¶
openssl enc -d -aes-256-cbc -pbkdf2 -in patient_record.enc -out patient_recovered.txt
cat patient_recovered.txt
Use the same password (SecureKey123) when prompted.
πΈ Screenshot checkpoint: Take a screenshot showing successful decryption β the original plaintext recovered.
Step 1.5 β Try Decrypting with Wrong Password¶
Enter a wrong password. OpenSSL will fail with an error.
πΈ Screenshot checkpoint: Take a screenshot of the decryption failure with wrong password.
Part 2 β Asymmetric Encryption with RSA¶
Asymmetric encryption uses a key pair: a public key (shared with anyone) and a private key (kept secret). Data encrypted with the public key can only be decrypted with the private key.
Step 2.1 β Generate an RSA Private Key¶
πΈ Screenshot checkpoint: Take a screenshot showing the RSA private key file (just the header, not the full key).
Step 2.2 β Extract the Public Key¶
The public key can be shared freely β you give it to anyone who wants to send you encrypted messages.
πΈ Screenshot checkpoint: Take a screenshot of the public key output.
Step 2.3 β Encrypt with the Public Key¶
echo "Transfer $50,000 to account 9876" > secret_message.txt
openssl pkeyutl -encrypt -inkey public_key.pem -pubin -in secret_message.txt -out encrypted_message.bin
cat encrypted_message.bin
The message is now encrypted β only the holder of the private key can read it.
πΈ Screenshot checkpoint: Take a screenshot of the unreadable encrypted binary.
Step 2.4 β Decrypt with the Private Key¶
openssl pkeyutl -decrypt -inkey private_key.pem -in encrypted_message.bin -out decrypted_message.txt
cat decrypted_message.txt
πΈ Screenshot checkpoint: Take a screenshot showing the decrypted message.
Part 3 β Digital Signatures¶
A digital signature proves that a message came from who it claims to come from and has not been altered. The sender signs with their private key; anyone verifies with the public key.
Step 3.1 β Sign a Document¶
echo "I authorize this transaction. - Dr. Chen" > authorization.txt
openssl dgst -sha256 -sign private_key.pem -out authorization.sig authorization.txt
ls -la authorization.sig
Step 3.2 β Verify the Signature¶
Expected output: Verified OK
πΈ Screenshot checkpoint: Take a screenshot showing "Verified OK".
Step 3.3 β Tamper and Re-Verify¶
echo "I authorize this transaction AND a second one. - Dr. Chen" > authorization.txt
openssl dgst -sha256 -verify public_key.pem -signature authorization.sig authorization.txt
Expected output: Verification Failure β tampering detected!
πΈ Screenshot checkpoint: Take a screenshot showing "Verification Failure" after tampering.
Part 4 β Inspecting a Real TLS Certificate¶
TLS certificates are how websites prove their identity using asymmetric cryptography.
Step 4.1 β Download and Inspect a Certificate¶
openssl s_client -connect google.com:443 -showcerts </dev/null 2>/dev/null | \
openssl x509 -noout -text | head -40
πΈ Screenshot checkpoint: Take a screenshot showing the certificate details β Subject, Issuer, validity dates, and key info.
Step 4.2 β Key Fields to Identify¶
From the output, find and note: - Subject: who the certificate belongs to - Issuer: who signed/vouched for it (Certificate Authority) - Not Before / Not After: validity period - Public Key Algorithm: RSA or EC - Key Size: 2048-bit, 4096-bit, etc.
Type exit when done.
Cleanup¶
Lab Assessment¶
Screenshot Submission Checklist¶
- [ ]
screenshot-07aβ Encrypted file (unreadable ciphertext) - [ ]
screenshot-07bβ Successful decryption (plaintext recovered) - [ ]
screenshot-07cβ Decryption failure with wrong password - [ ]
screenshot-07dβ RSA private key header - [ ]
screenshot-07eβ RSA public key content - [ ]
screenshot-07fβ Encrypted binary message - [ ]
screenshot-07gβ Decrypted message with private key - [ ]
screenshot-07hβ Digital signature "Verified OK" - [ ]
screenshot-07iβ Digital signature "Verification Failure" after tampering - [ ]
screenshot-07jβ TLS certificate details from google.com
Reflection Questions¶
- What is the fundamental difference between symmetric and asymmetric encryption? When would you prefer each?
- In RSA encryption, you encrypt with the public key and decrypt with the private key. Why does it need to be done in this specific order?
- How do digital signatures prove both authenticity (who sent it) and integrity (it wasn't changed)? Use Part 3 of this lab to explain.
- Looking at the TLS certificate for google.com: what does the "Issuer" field mean? Why can't a website just issue its own certificate and have browsers trust it?
Grading Rubric
- Screenshots complete and clearly labeled: 40 points
- Symmetric vs asymmetric comparison noted: 20 points
- Reflection questions answered thoughtfully: 40 points
- Total: 100 points