Skip to content

EC key pair generator

Generate an elliptic curve key pair on P-256, P-384 or P-521, as PEM and as JWK, in your browser.

Runs in your browser. Nothing you paste is sent to us.

Settings

Note that ES512 uses P-521, not a 512-bit curve.

Public key (JWK)
 
Private key (JWK)
 
Keep the private key private
The private JWK holds d, the secret part. Publish only the public JWK, for example in a JWKS.

PEM

Private key (PKCS#8 PEM)
 
Public key (SPKI PEM)
 
Made in this browser with Web Crypto and not stored anywhere. The kid is the key’s RFC 7638 thumbprint.

How to use it

  1. Choose the curve: P-256 for ES256, P-384 for ES384, P-521 for ES512.
  2. Copy the public JWK to publish, for example in a JWKS.
  3. Copy the private key as a JWK or as PKCS#8 PEM.
  4. Press Generate a new pair for another key.

What to know

Elliptic curve keys are much smaller than RSA keys of similar strength: a P-256 key matches roughly a 3072-bit RSA key. Signatures are smaller and faster to make too.

ES512 uses the P-521 curve, not a 512-bit one; the 512 refers to SHA-512.

Keycloak can sign tokens with ECDSA through its ecdsa-generated key provider. Choose the realm’s or a client’s signature algorithm (ES256 and so on) to use it.

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

CurveAlso calledJWT algorithmSecurity strengthSignature size in a JWT
P-256secp256r1, prime256v1ES256128 bits64 bytes
P-384secp384r1ES384192 bits96 bytes
P-521secp521r1ES512256 bits132 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.

The same ES256 signature in two encodings
JWS (ES256):  r (32 bytes) || s (32 bytes)        = 64 bytes
DER:          SEQUENCE { INTEGER r, INTEGER s }   = about 70 to 72 bytes

What the tool gives you

  • A public JWK with kty EC, crv, x and y, plus kid, use sig and alg.
  • 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 kid equal to the key’s RFC 7638 thumbprint, the SHA-256 hash of crv, kty, x and y.
Shape of the public JWK (placeholders)
{
  "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

  1. Choose the curve. Use P-256 unless something requires another.
  2. Copy the public JWK to wherever verifiers fetch keys, such as your service’s JWKS.
  3. Copy the private key, as JWK or PKCS#8 PEM, straight into a secrets manager or key store.
  4. 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 d is 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.

Useful OpenSSL commands for EC keys
# 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.txt

OpenSSL 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.

Questions

Frequently asked questions

Should I use EC or RSA keys for JWT signing?

Both are secure. EC keys (ES256) give smaller tokens and faster signing; RSA (RS256) is supported by more older libraries. Choose ES256 when every verifier supports it.

Is ES512 a 512-bit curve?

No. ES512 is ECDSA on the P-521 curve with SHA-512. The name refers to the hash.

Why do my ES256 signatures change every time?

ECDSA uses a fresh secret number for each signature, so the same input gives different signatures. All of them verify with the same public key.

What is the difference between the public and private JWK?

The private JWK adds the field d, the secret number. Publish only the public JWK, with kty, crv, x and y.

Is P-256 secure?

Yes. P-256 provides about 128 bits of security, comparable to a 3072-bit RSA key, and has no known practical attack.

Can Keycloak sign tokens with ES256?

Yes. Add an ecdsa-generated key provider to the realm and choose ES256 as the default signature algorithm, or per client. Check that your applications support ES256 first.

How do I convert an EC key from PKCS#8 to SEC1 format?

With OpenSSL 3: openssl pkey -in key.pem -traditional writes the EC PRIVATE KEY form. Older OpenSSL versions use openssl ec -in key.pem.

Why is a P-521 private key 66 bytes?

The private number can be up to 521 bits long, which needs 66 bytes. That is why the x, y and d values in a P-521 JWK are 66 bytes each, not 64.

Rather not run Keycloak yourself?

We run it for you on a cluster of your own, with backups, upgrades and written support. Starter and Premium begin with a 7-day trial.