Cyberlium

Cryptography › Module 4 › Lesson 3

BeginnerModule 4Lesson 3/4

Lab — Encrypt & Verify a File

Hash and encrypt a sample file with OpenSSL, then verify integrity

25 min+19 XP3 quiz
Module progress3 of 4

Opening

Lab: SHA-256 a toy file, AES-encrypt it with a lab passphrase you will not reuse, decrypt, confirm the digest matches.

Integrity and confidentiality on one object you created. First you fingerprint lab.txt with SHA-256 (hashing is not encryption — Module 1). Then you encrypt the file with OpenSSL AES using a lab passphrase that is not your email, not your bank, not a reused vault secret. Then you decrypt to a second file and hash again. Matching hex means the bytes survived the round trip. That is the mission. The files live in $HOME/cyberlium-lab and are chmod 600 so a shared account does not copy your passphrase-adjacent material. This is not a homebrew cipher. This is not attacking someone else’s ciphertext. This is not a cracking lab. openssl enc here is a teaching round trip; production apps should use high-level authenticated-encryption APIs, not copied flags forever. Next is the topic final quiz (twelve APPLY items; the subtitle still says 10-question), then Topic 9 Ethical Hacking (CEH v13) as authorized methodology — not a license to attack.

1. Order of operations: hash plaintext, encrypt, decrypt, hash again — compare hex, not vibes

openssl dgst -sha256 lab.txt prints a 64-character hex of the file bytes. Record it before encryption. openssl enc -aes-256-cbc -salt -pbkdf2 reads lab.txt and writes lab.txt.enc, prompting for a passphrase (or reading one you pass in a way that does not land in shell history if you can avoid it — prefer the prompt). Decrypt with matching flags to lab.out.txt. Hash lab.out.txt. The two hexes must match. If they do not, you decrypted with the wrong passphrase, hashed the ciphertext by mistake, or edited a file between steps. SHA-256 here is integrity of YOUR toy file, not password hashing (no salt+Argon2 on this file) and not cracking. AES here is symmetric encryption with a passphrase that OpenSSL turns into a key via PBKDF2 in this command line. CBC is what this copy-paste uses for a widely available teaching path; remember Module 2/4: real applications prefer authenticated encryption (GCM). If you flip one byte of lab.txt.enc, decrypt may error or yield garbage — a reminder that integrity of ciphertext is why AEAD exists. Do not turn that observation into a bit-flipping attack on someone else’s data.

The lab passphrase is a secret the moment you choose it. Do not type your real login. Do not reuse it tomorrow on a website. Do not put it in encrypt-lab-notes.txt, git, chat, or a screenshot. The notes record that you used a unique lab passphrase, the before/after SHA-256 hexes, MATCH, and the ethics line. chmod 600 on lab.txt, the ciphertext, the decrypt output, and the notes. Delete or keep the ciphertext in the lab folder — do not email it. Empty notes fail. Notes that contain the passphrase fail hygiene even if the hashes matched.

2. Scope: YOUR toy file in cyberlium-lab. Out: live keys, reused passphrases, attacking others’ ciphertext

lab.txt is a sentence you wrote. It is not /etc/shadow, not a customer export, not a classmate’s disk. openssl enc is not a warrant to decrypt files you found on a USB you do not own. Hashing is not rainbow tables. If a tutorial says “now crack the passphrase with a GPU,” that tutorial is not this lab. Topic 8’s earlier hash-crack lesson was toy-only on digests you created. This lab does not resume cracking. It proves a round trip.

3. Wrong vs right: encrypting other people’s files vs SHA-256 + AES round trip on YOUR lab.txt

Worked failure — same openssl enc, opposite target and leftover secrets. Right is matching hexes and a passphrase that dies with the lab.

  • Wrong

    Encrypt a file you do not own. Reuse your bank password as the passphrase. Write the passphrase into notes or git. Skip SHA-256 and call curl 200 “integrity.” Homebrew XOR instead of openssl. Bit-flip a stranger’s ciphertext as homework. chmod 644 on a shared PC. Paste live production keys into the command line.

  • Right

    Create lab.txt in $HOME/cyberlium-lab. SHA-256, AES-encrypt with a unique lab passphrase, decrypt, SHA-256 matches. Record hexes and MATCH in encrypt-lab-notes.txt without the passphrase. chmod 600. Next: Quiz — Cryptography Basics Final.

4. Hands-on: copy-paste OpenSSL, fill notes without the passphrase, lock the folder

Use Git Bash or WSL on Windows if openssl is missing from PowerShell. When openssl enc prompts, enter the lab passphrase twice for encrypt and once for decrypt. Do not pass -pass pass:yoursecret on a shared machine if the process list is visible — the interactive prompt is safer for teaching. Then lock files. Do not add a homebrew cipher “for comparison.”

Command guide

Toy file, SHA-256, AES round trip — $HOME/cyberlium-lab only

DEFENSIVE round trip on a file YOU created. Lab passphrase: unique, not reused on real accounts, NEVER written into notes/git/chat.

Command — copy this

mkdir -p "$HOME/cyberlium-lab"
cd "$HOME/cyberlium-lab"

Command — copy this

printf '%s
' 'cyberlium crypto lab — fictional sample file' > lab.txt

Command — copy this

echo "=== SHA-256 before encrypt ==="
openssl dgst -sha256 lab.txt

Record digest_before in encrypt-lab-notes.txt (NOT the passphrase).

Interactive passphrase prompt recommended (avoid -pass on shared hosts).

Command — copy this

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

Command — copy this

echo "=== SHA-256 after decrypt ==="
openssl dgst -sha256 lab.out.txt

digest_after must MATCH digest_before.

NEVER: openssl enc on someone else's files NEVER: reuse this passphrase as email/bank NEVER: echo the passphrase into a file

Command guide

encrypt-lab-notes.txt then chmod 600 — hexes and MATCH, no passphrase

Command — copy this

NOTES="$HOME/cyberlium-lab/encrypt-lab-notes.txt"
{
  echo "=== ENCRYPT AND VERIFY LAB ==="
  echo "file: $HOME/cyberlium-lab/lab.txt (toy text I created)"
  echo "hash: SHA-256 (integrity — NOT encryption, NOT cracking)"
  echo "enc: openssl enc AES-256-CBC + PBKDF2 (lab teaching path; apps should prefer AEAD APIs)"
  echo "digest_before:"
  echo "digest_after:"
  echo "compare: MATCH (expected) / DIFFER"
  echo "passphrase: unique lab secret — NOT written here, NOT reused on real accounts"
  echo "ethics: my file only; no live keys; no homebrew XOR; no attacking others' ciphertext"
} > "$NOTES"

Command — copy this

chmod 600 "$HOME/cyberlium-lab/lab.txt" \
          "$HOME/cyberlium-lab/lab.txt.enc" \
          "$HOME/cyberlium-lab/lab.out.txt" \
          "$NOTES"

Windows without chmod: WSL/Git Bash, or restrict the files in your profile.

NEVER: git add lab.txt.enc with a reused personal password NEVER: paste the passphrase into NOTES or chat NEVER: hash /etc/shadow or crack the passphrase with a wordlist

Mission: matching SHA-256 after AES decrypt (mode 600, passphrase not in the file)

Create a toy lab.txt in $HOME/cyberlium-lab. Record SHA-256. Encrypt with openssl enc AES (PBKDF2) using a lab passphrase you will not reuse. Decrypt. Confirm SHA-256 matches. Write both hexes and MATCH to encrypt-lab-notes.txt without the passphrase. chmod 600 the plaintext, ciphertext, output, and notes. Do not encrypt other people’s files. Do not homebrew a cipher. Do not commit live secrets.

Stuck? Ask Cyberlium AI Mentor

If “hashing and encrypting are the same step” still feels true, ask for a hint — not a cracker. Try: "Hint only: why SHA-256 before and after proves integrity, why openssl enc is encryption with a lab passphrase, and why that passphrase must not go in git, chat, or encrypt-lab-notes.txt?" You still run the round trip on YOUR file. No live keys. No others’ ciphertext. No homebrew XOR.

You used a hash for integrity and AES for confidentiality on a file you own, then locked the folder. Matching digests are byte equality after a round trip, not a CA, not a padlock, not permission to decrypt a stranger’s disk. Next — Quiz — Cryptography Basics Final — twelve APPLY items across hashing, encryption, TLS, and hygiene (the subtitle still says 10-question). Then Ethical Hacking (CEH v13): authorized methodology next, not a license to attack.

Knowledge Check

1

APPLY: digest_before on lab.txt equals digest_after on lab.out.txt. What did you prove, and what is this lab not?

Multiple choice

Knowledge Check

2

APPLY: True or False: Lab passphrases should be different from real account passwords, and writing the passphrase into encrypt-lab-notes.txt or git is required so the quiz can grade you.

True or False

Knowledge Check

3

APPLY: A classmate skipped SHA-256, used their email password, and wants to XOR-encrypt a USB they found. Correct pair for this mission?

Multiple choice

← Previous

Answer all 3 knowledge checks to continue. (0/3 answered)