ES256: short signatures, raw r and s, and one encoding trap
ES256 is ECDSA over the NIST P-256 curve with SHA-256. The issuer signs with a private scalar, the verifier checks with the corresponding public point, and the signature is much smaller than RSA: 64 bytes at a 128-bit security level. That combination — small keys, small signatures, fast verification — makes ES256 popular for mobile clients and high-volume APIs.
The curve and the hash are fixed by the algorithm name. ES256 means P-256 and SHA-256, not any 256-bit curve and not SHA-256 with P-384. A verifier must reject a key on a different curve rather than trying to make it work. This is one of the places where a permissive implementation creates interoperability problems that look like signature failures.
What the signature actually contains
ECDSA produces two integers, r and s, each in the range of the curve order. JOSE defines the signature as r || s, where each integer is encoded as a fixed-width big-endian byte string of the curve size: 32 bytes each for P-256, 48 for P-384, 66 for P-521. That gives 64, 96 and 132 bytes for ES256, ES384 and ES512.
Most general-purpose crypto APIs, including OpenSSL and many language bindings, use DER instead: a sequence of two integers with variable-length encoding and leading-zero handling. A DER signature for P-256 is typically 70 to 72 bytes. If you pass DER bytes to a JOSE verifier, the length check fails before any mathematics happens. If you pass raw bytes to a DER parser, it usually fails to parse. The fix is a conversion, or a library that exposes a JOSE-specific sign and verify function.
| Algorithm | Curve | Hash | Signature bytes | JWK crv |
|---|---|---|---|---|
| ES256 | P-256 | SHA-256 | 64 | P-256 |
| ES384 | P-384 | SHA-384 | 96 | P-384 |
| ES512 | P-521 | SHA-512 | 132 | P-521 |
Public keys as JWK
An EC public JWK has kty equal to EC, crv naming the curve, and x and y as base64url coordinates. The coordinates are fixed-width, so the base64url strings have a predictable length. A private JWK adds d; it must never appear in a JWKS. When importing, the browser needs both the curve and the hash: one to construct the key, the other to verify the signature.
PEM works too. An EC public key in SubjectPublicKeyInfo form names the curve in its algorithm identifier and carries the point in uncompressed form. A verifier that accepts PEM should check that the curve in the key matches the algorithm, because a P-384 key and an ES256 header are inconsistent even if both are valid objects.
The nonce problem
ECDSA signing picks a random nonce k. If the same k is used for two different messages with the same private key, anyone who sees both signatures can solve for the private key with simple algebra. This has happened in real systems when a virtual machine was cloned and its random state repeated. Modern libraries either use a strong system random source or RFC 6979 deterministic nonces derived from the message and private key.
For a verifier this history matters less, but it explains why ES256 signing keys deserve care in how they are generated and where signing happens. It is also a reason some teams choose Ed25519, which is deterministic by design and has no nonce to leak.
Verifying an ES256 token
Decode the header and confirm that alg is ES256. Select the key by kid from a trusted set, and check that its curve is P-256. Import it as an EC public key with the P-256 curve, then verify the signature over the exact header.payload bytes with SHA-256. The signature length must be exactly 64 bytes. If it is not, stop and convert the encoding rather than trying different keys.
The sample signer on this page generates a P-256 key pair in the browser, signs a token with it and shows the public JWK. Selecting Use in verifier loads the token, the algorithm and the key, so the whole path can be checked without any external service. For production, the same steps run against a JWKS and a key cache.
When to choose ES256
Choose ES256 when token size and verification speed matter, when the client platform has good P-256 support — which essentially all modern platforms do — and when you want asymmetric verification without the size of RSA. Choose ES384 or ES512 when policy requires a higher security level, accepting larger signatures and slightly slower operations. Choose EdDSA when you want the simplest modern option and both sides support it.
If an ECDSA signature has the wrong length, it is an encoding problem, not a wrong-key problem. Check the length before changing the key.
Sources
- RFC 7518 §3.4 — ECDSA signatures
- RFC 6979 — Deterministic ECDSA and DSA
- RFC 7517 §4 — JWK parameters for EC keys
Questions
Why is my ES256 signature 70 bytes instead of 64?
That is a DER-encoded ECDSA signature. JOSE requires the raw concatenation of r and s, each padded to 32 bytes for P-256. A DER signature varies in length because it strips leading zeros. Convert DER to raw before putting it in a JWT, or use a JOSE library that does it for you.
Which curve does ES512 use?
P-521, not P-512, with SHA-512. The names are historical. ES256 is P-256 with SHA-256, ES384 is P-384 with SHA-384, and ES512 is P-521 with SHA-512. Do not assume the number in the algorithm name is the curve size for ES512.
Is ECDSA deterministic?
Standard ECDSA uses a random nonce k for each signature. If k repeats, the private key can be recovered, which is why a broken random generator is catastrophic for ECDSA. Some implementations use RFC 6979 deterministic nonces. EdDSA avoids the problem by design, which is one reason it is attractive for new systems.
Generate an ES256 sample in the signer, then verify it with the exported public JWK.
Open the verifierWritten against the JOSE specifications (RFC 7515–7519), RFC 7636 and RFC 8037; every example can be reproduced in the verifier linked above.
Back to the guides