Blog - How asymmetric encryption works
Public and private keys, RSA in short, digital signatures, key exchange, and common implementation pitfalls.
- Author
- 2code
- Published
- Tags
- cryptography
- RSA
- security
Asymmetric encryption (public-key cryptography) uses a key pair: a public key (safe to share) and a private key (kept secret). An operation that is easy one way is practically irreversible without the secret.
Intuition
Think of a mailbox with two locks:
- anyone can drop a letter by locking it with the public key,
- only the owner can open it with the private key.
Mathematically we use a one-way function with a trapdoor: is easy, is hard — unless you know secret .
RSA in short
Pick large primes , set , . Public exponent (e.g. ), private such that:
Encrypt message (after proper padding):
Decrypt:
Security relies in part on the hardness of factoring .
Two main uses
…
…
- Confidentiality — encrypt with the recipient’s public key.
- Digital signature — sign with the private key; anyone verifies with the public key.
In TLS/HTTPS, asymmetric crypto usually does not encrypt all traffic: it authenticates parties and agrees a session key (AES, etc.), because symmetric crypto is cheaper.
ECDH — agreeing on a secret
With elliptic curves, parties derive a shared secret without sending it. Alice has , Bob , base point :
An observer sees and but cannot recover without solving the discrete log.
Common pitfalls
- No padding (raw RSA) — attackable; use OAEP / PSS.
- Mixed key roles — signing keys ≠ encryption keys (separate pairs / certs in practice).
- Weak entropy when generating or RNG seeds.
- Security through obscurity — the algorithm can be public; the secret is the private key.
Takeaway
Asymmetry solves trust bootstrapping (who is who, how to start safely), not bulk data encryption. In production: asymmetric at the handshake + symmetric for the session.