RSA
A public-key cryptosystem used for encryption and digital signatures, invented by Rivest, Shamir, and Adleman in 1977. RSA security relies on the computational difficulty of factoring large integers. RSA-2048 is the current minimum recommended key size for secure operations.
RSA (Rivest–Shamir–Adleman) is a public-key cryptosystem invented in 1977 by Ron Rivest, Adi Shamir, and Leonard Adleman. It uses a key pair: a public key that anyone can obtain, and a private key that only the owner holds. Data encrypted with the public key can only be decrypted with the private key, and messages signed with the private key can be verified by anyone with the public key.
Key Generation
RSA key generation:
- Choose two large random prime numbers
pandq - Compute
n = p × q(the modulus) - Compute
λ(n) = lcm(p−1, q−1) - Choose
e = 65537(standard public exponent) - Compute
dsuch thatd × e ≡ 1 (mod λ(n)) - Public key:
(n, e)| Private key:(n, d)
Security relies on: knowing n but not p and q, factoring n is computationally infeasible for large keys.
Key Sizes
| Key Size | Security Level | Status |
|---|---|---|
| 512 bit | None | Broken (1999) |
| 1024 bit | None | Broken (2010) |
| 2048 bit | ~112 bits | Current minimum |
| 3072 bit | ~128 bits | Recommended |
| 4096 bit | ~140 bits | High security |
NIST recommends 2048 bits as the minimum for RSA through 2030, with 3072+ recommended beyond that.
RSA in Practice
RSA is rarely used to encrypt data directly — it is slow and limited to encrypting data smaller than the key size. In practice:
TLS handshake:
1. Server sends RSA public key (in certificate)
2. Client generates random AES session key
3. Client encrypts session key with RSA public key
4. Server decrypts session key with RSA private key
5. Both parties use AES for the actual data
JWT RS256
JWT's RS256 algorithm uses RSA-PKCS1v1.5 with SHA-256:
- Auth server signs JWT with private RSA key
- All services verify JWT signature with public key
- Public key can be published openly (JWKS endpoint)
RSA vs ECC
Elliptic Curve Cryptography (ECC) achieves equivalent security with much smaller keys. A 256-bit ECC key provides approximately the same security as a 3072-bit RSA key. Modern systems prefer ECDSA (ES256) over RSA for JWT signing and TLS, but RSA remains widespread for compatibility.