Cryptography › Module 4 › Lesson 3
Lab — Encrypt & Verify a File
Hash and encrypt a sample file with OpenSSL, then verify integrity
Opening
Integrity + confidentiality on one file
Create a sample file, record its SHA-256, encrypt it, decrypt it, and confirm the hash still matches. Use a lab passphrase you will not reuse elsewhere.
1. Step 1 — Create and hash
Create sample + SHA-256echo cyberlium-crypto-lab > lab.txt openssl dgst -sha256 lab.txt
echo cyberlium-crypto-lab > lab.txt openssl dgst -sha256 lab.txt
2. Step 2 — Encrypt / decrypt
AES-256-CBC with PBKDF2 (lab passphrase)openssl enc -aes-256-cbc -salt -pbkdf2 -in lab.txt -out lab.txt.enc openssl enc -d -aes-256-cbc -pbkdf2 -in lab.txt.enc -out lab.out.txt openssl dgst -sha256 lab.out.txt
openssl enc -aes-256-cbc -salt -pbkdf2 -in lab.txt -out lab.txt.enc openssl enc -d -aes-256-cbc -pbkdf2 -in lab.txt.enc -out lab.out.txt openssl dgst -sha256 lab.out.txt
The before/after digests should match. If you change one byte of lab.txt.enc and try decrypt, you should get an error or garbage—depending on mode and tooling—reminding you why authenticated encryption matters in real apps.
Complete encrypt & verify lab
Hash lab.txt, encrypt to lab.txt.enc, decrypt to lab.out.txt, and confirm SHA-256 matches. Keep passphrases out of screenshots you share.
Knowledge Check
Comparing SHA-256 before encrypt and after decrypt checks:
Multiple choice
Knowledge Check
True or False: Lab passphrases should be different from real account passwords.
True or False