Cryptography › Module 2 › Lesson 2
Asymmetric Encryption (RSA)
Public/private key pairs: encrypt with one key, decrypt with the other
Opening
Publish a padlock. Keep the only key that opens it. That is how AES keys cross a network you do not already trust.
AES was fast and hungry for a shared secret. RSA (and modern elliptic-curve cousins) answer the hunger with a key pair: a public key you can post, and a private key that must never leave the owner. Anyone can encrypt a small blob to the public key; only the private key decrypts. Flip the job and the same pair signs (next-plus-one lesson). The cost is speed. RSA is not how you encrypt a two-hour video. It is how you wrap a fresh AES session key, or prove a signature, then let AES do the bulk work — the hybrid model TLS will use in Module 3. This lesson generates a TOY RSA key with openssl genrsa in $HOME/cyberlium-lab, encrypts a tiny note YOU wrote, decrypts it, then you delete the key. You will not factor moduli. You will not “break RSA.” You will not point tools at a bank or a classmate. 2048-bit is the lab floor. Lab material is not a production identity. Generating a key is not proof you are cyberlium.com — that is PKI, next.
1. Two keys, opposite jobs: public is shareable, private is secret
A key pair is generated together. The public key can sit in a file, a certificate, a homepage. The private key is a secret on the same order as a password — worse, because it is long, copyable, and sufficient. Encrypt-to-owner: sender uses the public key; only the private key holder recovers the plaintext. That solves a slice of AES’s distribution problem: Bob publishes a public key; Alice encrypts a random AES key to it; Bob decrypts that wrap; both then AES-encrypt the movie. Mallory can copy the public key and still cannot unwrap the AES key.
Mental model: a padlock anyone can snap shut (public) and only you can open (private). Do not stretch the metaphor into “public means unimportant.” If an attacker swaps Bob’s public key for their own, Alice encrypts to the attacker. That is why PKI exists: binding a name to a public key. This lesson only builds the pair. Treat a raw .pem sitting in a lab folder as a toy, not as “I am the bank.” Anyone can run genrsa. Anyone includes you, a phishing kit, and a well-meaning intern who emailed private.pem to themselves “for backup.”
Support map — what each half is allowed to do. Mixing the halves is how people paste private keys into tickets.
Public key
Shareable. Encrypt to the owner, or verify a signature. Not a password. Still needs identity binding (PKI).
Private key
Secret. Decrypts or signs. chmod 600. Never git, never Slack, never a screenshot. Delete toys when the lab ends.
Not interchangeable with AES
RSA does not replace AES for bulk data. AES does not replace RSA for “I never met Bob.” Hybrid uses both.
2. RSA is slow: wrap keys and sign; do not AES-replace a video file
RSA math on large integers is expensive compared with AES on a stream of blocks. A 2048-bit RSA encryption also has a size cap: you can feed it only a small number of bytes (modulus size minus padding). That is a feature of the design, not a bug to “fix” by splitting a movie into a thousand RSA chunks. The professional pattern is hybrid encryption: RSA (or a modern key-agreement) protects a random AES key; AES-GCM (or similar) protects the payload. TLS does a version of this every time the padlock works. Preview, not a handshake dump — Module 3 walks the TLS dance.
If a tutorial encrypts a whole disk with “only RSA” or claims RSA is obsolete because AES exists, they skipped the hybrid sentence. If a tutorial says beginners should factor a 2048-bit modulus “to understand attacks,” they skipped ethics and arithmetic. Factoring a toy 32-bit demo in a number-theory class is not this course. Attacking a live site’s certificate modulus is not a lab. You will generate, wrap a tiny note, delete. Literacy includes knowing RSA-OAEP and PSS exist as padding; the lab may use openssl’s default encrypt path on a few bytes. Do not homebrew padding. Do not roll a cipher “because RSA felt heavy.”
3. 2048 bits and up: toy keys you delete are not production identities
Key length is not a vibe. 1024-bit RSA is retired for security use. 2048-bit is a common baseline you will still see; 3072 or 4096 appear where policy asks. Newer designs often prefer elliptic curves (smaller keys, similar job). This module teaches RSA because openssl genrsa is visible and the public/private story is the same shape you need for PKI and signatures. Follow current guidance for anything that leaves the lab. A 2048-bit toy key that sat in Downloads for a year is not “hardened.” It is a forgotten secret. Delete it after the decrypt works.
openssl genrsa writes a private key; openssl rsa -pubout extracts the public half. A short-lived unencrypted toy key in cyberlium-lab that you delete is acceptable for this hour. For anything real, protect the private key with a passphrase you do not reuse from email, and with OS ACLs. Never keep a joke bank-prod.pem.
4. Hybrid TLS preview: asymmetric handshake, symmetric bulk, certificates later
When a browser speaks HTTPS, it does not RSA-encrypt every image tile. It uses asymmetric (or key-agreement) operations to land on session secrets, then AES-GCM or another AEAD for the bytes. Certificates (PKI) tell the browser which public key is allowed to speak for example.com. You now have the three nouns: AES (bulk confidentiality), RSA-class pairs (wrap or sign), PKI (name binding). Module 3 puts them in order as a handshake. Do not skip to “decrypt HTTPS of a site I do not own.” You cannot, and trying is not a homework stretch.
5. Wrong vs right: breaking moduli vs a toy genrsa you delete
Worked failure — treating RSA as a CTF against the internet, or as a bulk video codec.
Wrong
Download a site’s certificate and try to factor the modulus. Run a “RSA cracker.” Encrypt a 4 GB video with raw RSA. Commit toy-rsa-private.pem to GitHub. Email the private key. Claim genrsa means you are the bank. Homebrew a public-key scheme from blog comments. Point pkeyutl at someone else’s files. Any attack on keys you do not own is out of scope and can be illegal.
Right
cd $HOME/cyberlium-lab. openssl genrsa 2048 (or stronger) to a toy private pem; pubout the public half; encrypt a tiny note YOU wrote with the public key; decrypt with the private key; chmod 600; write notes that RSA is slow and hybrid with AES; delete the toy private key when the round-trip is done. Next — PKI — why a key pair is not an identity.
6. Practical: openssl genrsa of a TOY key, wrap YOUR tiny note, delete the key
Keep the plaintext tiny — RSA encrypt is for a small blob, which is the teaching point for hybrid wrapping. Do not add a factoring script “to see.” Do not reuse this key on a real server. Git Bash / WSL / macOS / Linux as usual; restrict ACLs on Windows if chmod is missing. After cat shows the note, remove the private key so the lab does not become a forgotten identity.
Command guide
DEFENSIVE RSA lab — TOY key in $HOME/cyberlium-lab, then delete
DEFENSIVE. Generate a TOY RSA key YOU will delete. NEVER factor moduli. NEVER attack a site or someone else's keys. NEVER encrypt bulk video with raw RSA. NEVER git the private pem.
Command — copy this
mkdir -p "$HOME/cyberlium-lab" cd "$HOME/cyberlium-lab"
2048-bit floor for this course. This is a TOY. Not a bank identity.
Command — copy this
openssl genrsa -out toy-rsa-private.pem 2048 openssl rsa -in toy-rsa-private.pem -pubout -out toy-rsa-public.pem
Command — copy this
chmod 600 toy-rsa-private.pem toy-rsa-public.pem 2>/dev/null || true
Tiny note only — RSA encrypt is size-capped (hybrid AES is for bulk).
Command — copy this
printf 'lab wrap — delete me ' > toy-rsa-note.txt
Optional command
OpenSSL 3: pkeyutl. (Older docs may show rsautl — same idea, tiny input.)
Command — copy this
openssl pkeyutl -encrypt -pubin -inkey toy-rsa-public.pem \ -in toy-rsa-note.txt -out toy-rsa-note.enc
Command — copy this
openssl pkeyutl -decrypt -inkey toy-rsa-private.pem \ -in toy-rsa-note.enc -out toy-rsa-note.out
Command — copy this
cat toy-rsa-note.out
Must match the tiny note. If it fails, the file was too big or the key mismatch.
Command — copy this
{
echo "=== RSA LAB NOTES (no private key material) ==="
echo "public: shareable — encrypt-to-owner or verify signatures"
echo "private: secret — decrypt or sign; chmod 600; delete toys"
echo "size: 2048-bit toy; follow current guidance off-lab"
echo "slow: wrap AES keys / signatures, NOT bulk video"
echo "hybrid_tls_preview: asymmetric (or KEM) then AES-GCM bulk"
echo "ethics: MY files; no factoring; no site attacks; delete toy key"
} > rsa-lab-notes.txt
chmod 600 rsa-lab-notes.txt toy-rsa-note.txt 2>/dev/null || trueDELETE the toy private key when the round-trip is confirmed:
Command — copy this
rm -f toy-rsa-private.pem toy-rsa-note.enc
Keep public + notes if you want them for the signatures lesson, or delete all toys.
NEVER: openssl s_client "attacks" or modulus factoring NEVER: cp toy-rsa-private.pem into a web root NEVER: reuse this key as a production SSH or TLS identity
Mission: toy genrsa, tiny wrap, delete the private key
1) In $HOME/cyberlium-lab, openssl genrsa 2048 (or stronger) and extract the public key. 2) Encrypt a tiny note YOU wrote with the public key; decrypt with the private key; confirm the text. 3) Write rsa-lab-notes.txt: public vs private, 2048+ bits, slow/hybrid with AES, TLS preview — no key bytes in the notes. chmod 600. Delete the toy private key. Never factor moduli. Never attack sites.
Stuck? Ask Cyberlium AI Mentor
If “public key should stay as secret as a password” or “RSA should encrypt the whole movie” still blurs, ask for a hint — not a factoring guide. Try: "Hint only: why the public key is shareable, why the private key is not, why RSA wraps AES keys instead of bulk video, and why I must delete this toy genrsa key?" You still run the tiny encrypt on YOUR file. No moduli attacks. No production identities.
You now have a pair: public shareable, private secret, 2048-bit toy deleted after a tiny wrap. AES stays the bulk engine; RSA-class math carries keys and, soon, signatures. The remaining lie is “I generated a key, therefore I am the site.” Next — Public Key Infrastructure (PKI) — certificates bind names to public keys, chains walk to a trust anchor, and Module 3 will introduce CAs. Still no breaking RSA. Still $HOME/cyberlium-lab.
Knowledge Check
APPLY: A classmate publishes toy-rsa-private.pem “so the team can encrypt to me,” wants to RSA-encrypt a course video, and asks for a script to factor a bank’s modulus “as homework.” What is the pair for, and what do you refuse?
Multiple choice
Knowledge Check
APPLY: You need to send a large log you own to a teammate who already has your public key on a channel you trust for identity (lab fiction). Which design matches this module, and where do files live?
Multiple choice
Knowledge Check
APPLY: True or False: openssl genrsa on your laptop proves you are paypal.com, 1024-bit keys are enough, and you should keep the toy private key forever in Downloads in case a later lesson needs it for attacking sites.
True or False