What an elliptic curve key pair is
Elliptic curve cryptography (ECC) is a family of public-key algorithms built on the mathematics of points on a curve. Like RSA, a key pair has a private key that signs and a public key that verifies. Unlike RSA, the keys are small: a P-256 key gives security comparable to a 3072-bit RSA key with a 32-byte private key.
For signatures, the elliptic curve algorithm is ECDSA. In JSON Web Tokens it appears as ES256, ES384 and ES512. Smaller keys mean smaller signatures, smaller tokens and faster signing.
This tool generates ECDSA key pairs on the three NIST curves that Web Crypto supports, and gives you the keys as JWK and as PEM.
The three curves
| Curve | Also called | JWT algorithm | Security strength | Signature size in a JWT |
|---|---|---|---|---|
| P-256 | secp256r1, prime256v1 | ES256 | 128 bits | 64 bytes |
| P-384 | secp384r1 | ES384 | 192 bits | 96 bytes |
| P-521 | secp521r1 | ES512 | 256 bits | 132 bytes |
Note the naming trap: ES512 uses the P-521 curve, not a 512-bit one. The 512 refers to SHA-512, the hash. A P-521 private key is 66 bytes because 521 bits do not fit in 65.
P-256 is the common choice. It is supported nearly everywhere, fast, and strong enough for almost any use. P-384 is used where a policy asks for 192-bit strength.
How ECDSA signatures differ from RSA
Two practical differences catch people out.
Signatures use a random nonce
Each ECDSA signature uses a fresh secret number. Signing the same token twice gives two different signatures, both valid. That is normal. If the number were ever reused or predictable, the private key could be calculated from two signatures, which is why good implementations either use a strong random source or derive the number deterministically as RFC 6979 describes.
Two signature encodings
An ECDSA signature is two numbers, r and s. JWTs store them as raw bytes joined together, each padded to the curve size, as RFC 7518 requires. X.509 certificates and most other formats store them as a DER sequence instead. Passing a DER signature where a JWT library expects raw bytes, or the reverse, is a common cause of "invalid signature" errors.
JWS (ES256): r (32 bytes) || s (32 bytes) = 64 bytes
DER: SEQUENCE { INTEGER r, INTEGER s } = about 70 to 72 bytesWhat the tool gives you
- A public JWK with
ktyEC,crv,xandy, pluskid,usesigandalg. - A private JWK, which adds
d, the private number. - The private key as PKCS#8 PEM (
BEGIN PRIVATE KEY) and the public key as SPKI PEM (BEGIN PUBLIC KEY). - A
kidequal to the key’s RFC 7638 thumbprint, the SHA-256 hash ofcrv,kty,xandy.
{
"kid": "<RFC 7638 thumbprint>",
"use": "sig",
"alg": "ES256",
"kty": "EC",
"crv": "P-256",
"x": "<32 bytes, Base64url>",
"y": "<32 bytes, Base64url>"
}It does not produce the older SEC1 EC PRIVATE KEY PEM format, and it does not generate Ed25519 keys. Use openssl pkey to convert PKCS#8 to SEC1 if a tool needs it.
How to generate an EC key pair
- Choose the curve. Use P-256 unless something requires another.
- Copy the public JWK to wherever verifiers fetch keys, such as your service’s JWKS.
- Copy the private key, as JWK or PKCS#8 PEM, straight into a secrets manager or key store.
- Press Generate a new pair if you need another key; each is independent.
Where EC keys are used in identity work
Anywhere a token or proof is signed often, small and fast keys pay off.
Signing tokens in Keycloak
Keycloak can sign tokens with ECDSA. Add an ecdsa-generated key provider to the realm under Keys, Providers, choosing the curve, then set ES256 as the realm’s default signature algorithm or as a client’s access token signature algorithm. Clients then receive smaller tokens.
Before switching, check that every application that verifies Keycloak tokens supports ES256. Most current JWT libraries do; some older ones only handle RS256.
Client authentication with private_key_jwt
A confidential client can authenticate to Keycloak with a JWT signed by its own private key, instead of sending a client secret. An EC key is a good fit: the client signs a small assertion per token request, and Keycloak verifies it with the public key from the client’s Keys tab or the client’s JWKS URL.
DPoP proofs
DPoP (RFC 9449) binds tokens to a key held by the client. The client signs a short proof JWT for each request, with the public key in its header. ES256 keys are a common choice because proofs are made often and should be small. See the DPoP proof generator.
Signing your own tokens
Services that issue their own JWTs, such as an internal API gateway, can sign with an EC key and publish the public JWK at a JWKS URL.
Common mistakes
- Publishing the private JWK. Check that
dis absent from anything you publish. - Calling P-521 "P-512" or picking a 512-bit curve for ES512. The curve is P-521.
- Feeding DER-encoded signatures to a JWT verifier, or raw signatures to an X.509 tool.
- Expecting two signatures of the same data to be identical. With ECDSA they differ.
- Using an exotic curve such as secp256k1 for JWTs. It has a JOSE name (ES256K), but support is limited.
Security notes
The key is generated in your browser by Web Crypto and sent nowhere. Treat the private key as a credential: anyone who has it can sign tokens your services will trust.
All three curves are NIST curves approved for federal use. P-256 remains a sound choice; there is no known practical attack on it.
For keys that must last many years, keep an eye on post-quantum guidance. Like RSA, elliptic curve signatures would be broken by a large quantum computer, and standards bodies are publishing replacements. That is a planning matter, not a reason to avoid ECDSA today.
Best practices
- Default to P-256 and ES256.
- Give each key a stable
kid, such as its thumbprint, and publish public keys through a JWKS so you can rotate. - Keep at least two keys published during a rotation: the new one signing and the old one still verifying.
- Store private keys in a secrets manager or key service, never in source control.
- Test every verifier before moving a production issuer from RS256 to ES256.
Checking an EC key with OpenSSL
Before you deploy a key, confirm that the private and public halves belong together and that the curve is what you expect.
# Show the curve and the public point of a private key
openssl pkey -in private.pem -noout -text
# Derive the public key and compare it with the one you published
openssl pkey -in private.pem -pubout | diff - public.pem && echo match
# Sign and verify a test file
openssl dgst -sha256 -sign private.pem -out test.sig test.txt
openssl dgst -sha256 -verify public.pem -signature test.sig test.txtOpenSSL writes ECDSA signatures in DER form, so test.sig above is not the raw form a JWT uses. That is expected; it is the encoding difference described earlier.
EC P-256 or Ed25519?
Ed25519 is another elliptic curve signature scheme, called EdDSA in JOSE. It is fast, deterministic by design and avoids the nonce pitfalls of ECDSA. Support in browsers, JWT libraries and identity products has grown but is still less universal than ES256, which is why this tool sticks to the NIST curves. If every party in your system supports EdDSA, it is a good choice too.