DevKits
Concept

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