By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
Zero-fluff, hyper-practical guide for real-world use and exam prep
You’re a security engineer at a fintech startup. Your team just migrated a legacy payment processing system to the cloud, but the database still stores customer credit card numbers in plaintext. Your CISO drops a compliance audit on your desk: "PCI DSS requires encryption at rest and in transit. Fix it by EOD."
This is where symmetric and asymmetric encryption save the day.
Why this matters in production: - If you ignore encryption, you’re one breach away from front-page news (see: Equifax, Capital One). - If you use the wrong type, your app slows to a crawl (e.g., encrypting a 10GB database with RSA instead of AES). - If you misconfigure keys, you lock yourself out of your own data (e.g., losing an RSA private key = permanent data loss).
Real-world scenario: You’re deploying a new microservice. You need to:1. Encrypt sensitive config files (symmetric).2. Secure API communication (asymmetric + symmetric hybrid).3. Sign software updates (asymmetric).
This guide gives you the exact commands, configs, and pitfalls to do it right.
Prerequisites: - Linux/macOS terminal (or WSL on Windows). - openssl installed (sudo apt install openssl on Ubuntu).
openssl
sudo apt install openssl
openssl rand -hex 32 > aes_key.key # 256-bit (32-byte) key
Why? AES-256 requires a 256-bit key. rand -hex 32 generates 32 random bytes (64 hex chars).
rand -hex 32
openssl enc -aes-256-cbc -salt -in secret.txt -out secret.enc -pass file:aes_key.key
Flags: - -aes-256-cbc: AES-256 in CBC mode (Cipher Block Chaining). - -salt: Adds randomness to prevent rainbow table attacks. - -pass file:aes_key.key: Reads the key from a file.
-aes-256-cbc
-salt
-pass file:aes_key.key
openssl enc -d -aes-256-cbc -in secret.enc -out secret_decrypted.txt -pass file:aes_key.key
Verify:
diff secret.txt secret_decrypted.txt # Should show no differences
openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits:2048 openssl rsa -pubout -in private_key.pem -out public_key.pem
Why? genpkey is the modern way to generate keys (older tools like genrsa are deprecated).
genpkey
genrsa
echo "Top secret message" > message.txt openssl pkeyutl -encrypt -pubin -inkey public_key.pem -in message.txt -out encrypted.msg
Flags: - -pubin: Input is a public key. - -inkey public_key.pem: Public key file.
-pubin
-inkey public_key.pem
openssl pkeyutl -decrypt -inkey private_key.pem -in encrypted.msg -out decrypted.txt
cat decrypted.txt # Should show "Top secret message"
openssl dgst -sha256 -sign private_key.pem -out signature.bin message.txt
Why? dgst -sha256 creates a SHA-256 hash, then signs it with the private key.
dgst -sha256
openssl dgst -sha256 -verify public_key.pem -signature signature.bin message.txt
Expected output:
Verified OK
Answer: AES (symmetric) – faster for bulk data.
Key Sizes & Security
Answer: Equivalent security (ECC-256-RSA-3072).
Modes of Operation
Answer: GCM (Galois/Counter Mode) – combines encryption + integrity.
Digital Signatures
secret.txt
Solution:
# 1. Encrypt file with AES-256 openssl rand -hex 32 > aes_key.key openssl enc -aes-256-cbc -salt -in secret.txt -out secret.enc -pass file:aes_key.key # 2. Encrypt AES key with RSA openssl pkeyutl -encrypt -pubin -inkey public_key.pem -in aes_key.key -out aes_key.enc # 3. Sign the encrypted file openssl dgst -sha256 -sign private_key.pem -out signature.bin secret.enc # 4. Verify & decrypt openssl dgst -sha256 -verify public_key.pem -signature signature.bin secret.enc openssl pkeyutl -decrypt -inkey private_key.pem -in aes_key.enc -out aes_key_decrypted.key openssl enc -d -aes-256-cbc -in secret.enc -out secret_decrypted.txt -pass file:aes_key_decrypted.key
Why it works: - AES encrypts the data (fast). - RSA encrypts the AES key (secure key exchange). - RSA signs the file (proves authenticity).
openssl enc -aes-256-cbc
openssl enc -bf-cbc
openssl enc -des-ede3-cbc
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048
openssl ecparam -genkey -name prime256v1 -out ec_key.pem
aws kms encrypt --key-id alias/my-key --plaintext fileb://secret.txt
gpg --encrypt --recipient [email protected] secret.txt
vault kv put secret/myapp db_password=12345
Final Tip: Bookmark this guide. The next time you’re encrypting a database, signing a binary, or debugging a TLS handshake, you’ll know exactly what to do. ?
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.