33.4 Asymmetric Encryption
Asymmetric (public-key) encryption uses a key pair:
- the public key can be shared with everyone;
- the private key is kept secret by the owner.
What one key locks, only the other key opens. So:
| You want to | Use |
|---|---|
| Send a secret to Sneha | Encrypt with Sneha's public key – only her private key can open it |
| Prove a message came from you | Sign with your private key – anyone checks it with your public key |
Algorithms: RSA (2048-bit minimum, 3072+ preferred), ECC such as ECDSA and Ed25519 (smaller keys, same strength), and Diffie-Hellman / ECDHE for agreeing on a shared key over an open network.
Asymmetric crypto is slow, so real systems use it only to exchange or protect a symmetric key, then switch to AES. This mix is called hybrid encryption – it is exactly what TLS and PGP do.
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:3072 -out private.pem
openssl pkey -in private.pem -pubout -out public.pem
echo "Meeting at Shaniwar Wada 5pm" > msg.txt
openssl pkeyutl -encrypt -pubin -inkey public.pem -in msg.txt -out msg.enc
openssl pkeyutl -decrypt -inkey private.pem -in msg.enc
ssh-keygen -t ed25519 # your SSH keys are the same idea: id_ed25519 (private), id_ed25519.pub (public)
Ravindra Bagale's Tip
A private key is called "private" for a reason – never on email, WhatsApp or GitHub. Students accidentally push the .pem file to a repo. Share the public key; keep the private key only with you, with chmod 400.
Ravindra Bagale's Tip – मराठी
Private key चे नावच "private" आहे – ती email, WhatsApp किंवा GitHub वर कधीच नाही. Students चुकून .pem file repo मध्ये push करतात. Public key share करा, private key फक्त तुमच्याकडे, chmod 400 सोबत.
Ravindra Bagale's Tip – हिंदी
Private key का नाम ही "private" है – वह email, WhatsApp या GitHub पर कभी नहीं. Students गलती से .pem file repo में push कर देते हैं. Public key share करो, private key सिर्फ़ आपके पास, chmod 400 के साथ.
Lab
Generate an RSA key pair, give your public.pem to a partner, and ask them to encrypt a short message for you. Decrypt it with your private key. Then explain in two sentences why they could not decrypt their own encrypted message without your private key.
Extended teaching notes
Why this lesson matters
Cryptography fails when people invent it. Use standard libraries, modern algorithms (AES-GCM, TLS 1.2+, bcrypt/argon2) and protect keys in a KMS or secrets manager.
Where crypto shows up
[('Passwords', 'bcrypt/argon2/PBKDF2 via the framework hasher — never plain MD5/SHA1.'), ('TLS', "Terminate on ALB/nginx with ACM/Let's Encrypt; redirect HTTP to HTTPS."), ('JWT / API tokens', 'Short lifetime, rotate signing keys, store secrets outside Git.'), ('Disk / S3', 'Provider or customer-managed keys; least privilege on decrypt.')]
Mini case study
Suppose we are on a purple-team exercise for an Indian mid-size company (sample data). Red notes a technique from this lesson against a lab clone. Blue must show the control that stops it, the log that would have fired, and the ticket that hardens production. That is the standard this course trains you for.
Defender's worksheet (do this today)
- Write the lesson title, date and the exact lab target you are allowed to use.
- List three owned systems (VMs, apps, or cloud accounts) where this lesson applies.
- Run one safe check from the lesson on a lab system only. Paste the command and output.
- Write a two-sentence fix you would give a teammate.
- Name one related public advisory (CERT-In, CISA, NVD, or a vendor bulletin) with its date.
Indian workplace (sample data)
Suppose we are a junior analyst at Infosys, TCS, Wipro or a fintech SOC in Bengaluru/Pune. Turn this lesson into one checklist item with an owner, a due date and a place to store evidence (ticket + screenshot).
Global practice
Compare your notes with OWASP, CIS Benchmarks, NIST CSF/IR guidance or a cloud Well-Architected security question. Write five lines on what overlaps.
Everyday analogy
Explain the risk and the fix to a family member without jargon. If they can repeat the warning, you understand it well enough to teach juniors.
Key terms
- Control: a safeguard (patch, config, process, detection).
- Finding: a weakness backed by evidence.
- Remediation: the fix plus how you verified it.
- Scope: systems you have written permission to touch.
- Least privilege: only the access the task needs.
- Defence in depth: several layers so one failure does not end the story.
Common mistakes
- Skipping written permission "just for a quick scan".
- Practising on hostel, office or public targets without authorisation.
- Collecting tool output without writing the fix.
- Copying attack steps onto production to "verify". Defenders verify with versions, configs and patches.
- Publishing screenshots that contain secrets, cookies or internal hostnames.
Recap
- Evidence, fix, owner, date.
- Own lab only.
- Fix > spectacle.