Asymmetric Cryptography Explained — RSA, ECDSA, and When to Use Each
Asymmetric cryptography uses a public/private key pair: one key to encrypt/sign, the other to decrypt/verify. RSA and ECDSA are the two major families used in JWTs, TLS, SSH, and WebAuthn. This guide compares their key sizes, speed, and use cases.
Last updated:
Core Concepts
- RSA (Rivest-Shamir-Adleman)
- RSA security is based on the difficulty of factoring large composite numbers. Key sizes: 2048 bits (baseline, ~112-bit security), 3072 (~128-bit), 4096 (~144-bit). RSA can both encrypt (OAEP) and sign (RS256, PS256). Signing is fast, verification is very fast, but RSA key generation is slow (seconds for 4096-bit) and signatures are large.
- ECDSA (Elliptic Curve Digital Signature Algorithm)
- ECDSA security is based on the discrete log problem over elliptic curves. Key sizes: P-256 (~128-bit security, equivalent to RSA-3072), P-384 (~192-bit), P-521 (~256-bit). Signatures are ~8x smaller and ~10x faster to generate than RSA. P-256 is used by TLS 1.3, WebAuthn, and most JWT deployments going forward.
- When to choose RSA vs ECDSA
- Choose ECDSA for new projects — smaller keys, smaller signatures, faster signing, no downside. P-256 is enough for 99% of use cases. Choose RSA only if you need compatibility with legacy systems that can't handle EC keys (rare in 2026), or if you need RSA-OAEP encryption (ECDSA is signing-only; EC-DH is encryption, but less widely supported than RSA-OAEP for envelope encryption).
- Ed25519 — the third option
- Ed25519 uses Edwards curves instead of NIST's Weierstrass curves. It's faster than ECDSA, more resistant to side-channel attacks, has deterministic signatures (no RNG failure risk), and produces shorter keys (32 bytes). Downside: not universally supported in JWT libraries yet (EdDSA is RFC 8037, but many signer/verifier implementations lag behind).
Frequently Asked Questions
Can I encrypt data directly with RSA?
Yes, but not large data. RSA-2048 can only encrypt ~190 bytes (after OAEP padding). For larger payloads, use hybrid encryption: generate a random AES-256 key, encrypt the payload with AES-GCM, then encrypt the AES key with RSA-OAEP. This is the standard envelope pattern used by PGP, TLS, and most encrypted-file formats.
How do key sizes compare?
P-256 ECDSA ≈ RSA-3072 in security strength (128-bit). P-384 ≈ RSA-7680 (192-bit). P-521 ≈ RSA-15360 (256-bit). ECDSA achieves equivalent security with much smaller key material. A 256-bit EC private key is 32 bytes; an equivalent RSA-3072 private key is ~384 bytes.
Try these related tools
RSA Key Generator →
Generate RSA key pairs (2048, 3072, or 4096 bits) online for OAEP encryption, PSS signing, or RS256 JWTs. Exports PKCS#8 private key + SPKI public key as PEM, JWK, or DER (hex/base64). 100% local — the Web Crypto API runs in your browser, private keys never leave the tab.
ECDSA Key Generator →
Generate elliptic-curve key pairs (P-256, P-384, P-521) for ECDSA signatures or ECDH key agreement. Exports PKCS#8 / SPKI PEM, JWK, and DER (hex/base64). Perfect for ES256/ES384/ES512 JWTs. 100% local via the Web Crypto API — the private key never leaves your browser.
RSA Encrypt / Decrypt →
Encrypt text with an RSA public key or decrypt ciphertext with the private key, using RSA-OAEP (SHA-256/384/512). Accepts PEM (PKCS#8 / SPKI) or JWK. 100% local — keys and plaintext never leave your browser tab.
JWT Generator →
Create signed JSON Web Tokens with HS256/384/512 (HMAC), RS256/384/512 (RSA), PS256/384/512 (RSA-PSS), or ES256/384/512 (ECDSA). Paste a raw secret, a PEM private key, or a JWK — signing runs entirely in your browser via the Web Crypto API.