Reading CBOR and COSE public keys: ES256, RS256, Ed25519
In one line: How the attestationObject CBOR map and the COSE key map (kty, alg, crv, x, y, n, e) are laid out, with byte-level examples and reconstruction steps.
A WebAuthn public key is not JSON. It is a COSE key encoded in CBOR, nested inside the CBOR map that is the attestationObject. Reading one means reading two levels of CBOR.
The minimum CBOR you need
| Major type | Meaning | Example |
|---|---|---|
| 0 | Unsigned integer | 0x01 = 1 |
| 1 | Negative integer | 0x26 = -7 (ES256 alg) |
| 2 | Byte string | 0x58 0x20 … = 32 bytes |
| 3 | Text string | 0x64 0x6e 0x6f 0x6e 0x65 = "none" |
| 4 | Array | 0x81 … |
| 5 | Map | 0xa3 … = three keys |
The attestationObject
a3 map(3) 63 666d74 "fmt" 64 6e6f6e65 "none" 67 61747453746d74 "attStmt" a0 map(0) ← empty for the none format 68 6175746844617461 "authData" 59 00a4 … bytes(164)
The COSE key map
| Key | Name | EC2 (P-256) | RSA | OKP (Ed25519) |
|---|---|---|---|---|
| 1 | kty | 2 | 3 | 1 |
| 3 | alg | -7 (ES256) | -257 (RS256) | -8 (EdDSA) |
| -1 | crv / n | 1 (P-256) | n (bytes) | 6 (Ed25519) |
| -2 | x / e | x (32 bytes) | e (usually 65537) | x (32 bytes) |
| -3 | y | y (32 bytes) | — | — |
Reconstructing from real bytes
a5 01 02 03 26 20 01 21 58 20 <x 32 bytes> 22 58 20 <y 32 bytes> │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ └ crv=1 │ └ y (-3) │ │ │ │ │ │ └ alg=-7 └ x (-2) │ │ │ │ │ └ kty=2 │ │ │ │ └ -1 │ │ │ └ -7 │ │ └ 3 │ └ 2 └ map(5)
To hand a P-256 key to another tool, build the uncompressed point 0x04 || x || y (65 bytes) or convert to the JWK {"kty":"EC","crv":"P-256","x":…,"y":…}. The coordinates are raw 32 bytes, not Base64URL, and leading zeros must be kept.
Algorithms you will meet
- ES256 (-7) — ECDSA P-256 with SHA-256, by far the most common. WebAuthn signatures are ASN.1 DER, and many libraries need converting to the raw r||s form before verifying.
- RS256 (-257) — RSASSA-PKCS1-v1_5 with SHA-256, seen with some Windows Hello and enterprise keys.
- EdDSA (-8) — Ed25519; short keys and deterministic signatures.
- PS256 (-37) — RSA-PSS, used by some security keys.
Converting to a form another tool accepts
Most verifiers want a JWK or a PEM public key, not COSE. For EC2, Base64URL-encode x and y without padding and set crv to P-256; for RSA, Base64URL-encode the unsigned big-endian modulus and exponent; for OKP, encode x and set crv to Ed25519. Never strip leading zero bytes from a coordinate: they are part of the fixed 32-byte length, and a shortened coordinate makes the key invalid.
Checking order
- Read kty first (2 = EC2, 3 = RSA, 1 = OKP).
- Confirm alg is in the list the server accepts.
- For EC2, check crv = 1 (P-256) and that x and y are 32 bytes each.
- For RSA, check that n is at least 256 bytes (2048 bits).
PasskeyLab's COSE table shows exactly these values and verifies signatures with the same key.
Decoding happens right in the browser. The payload you paste is not stored.
Open the PasskeyLab decoderFrequently asked questions
How do COSE keys differ from JWK?
COSE is a binary encoding over CBOR and JWK is JSON. The fields correspond, so kty, crv, x and y map one to one when converting.
Why is ES256 represented as -7?
COSE algorithm identifiers are negative integers from the IANA registry. -7 is ECDSA with SHA-256 and -257 is RSASSA-PKCS1-v1_5 with SHA-256.
Can a public key be reversed into a private key?
No. P-256 and RSA-2048 cannot be inverted with known methods, which is why storing the public key on a server is safe.
Sources
- RFC 8949 — Concise Binary Object Representation (CBOR)
- RFC 8152 — CBOR Object Signing and Encryption (COSE)
- W3C WebAuthn Level 3
Read next
- The WebAuthn registration and authentication ceremoniesWhat the browser, server and authenticator each build and verify during create and get, field by field, and where implementations usually go wrong.
- The authenticatorData byte layout and flag bitsOffsets for the 37-byte header, AAGUID, credential ID, COSE key and extensions, with a worked hex example and the meaning of every flag.
- RP ID and origin validation: why passkeys bind to the wrong siteHow rpIdHash is computed, the protocol, host and port rules for origins, and the subdomain and localhost exceptions, with real mismatch cases.