opyebPasskeyLab

Reading CBOR and COSE public keys: ES256, RS256, Ed25519

Key parsing · 8 min read

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 typeMeaningExample
0Unsigned integer0x01 = 1
1Negative integer0x26 = -7 (ES256 alg)
2Byte string0x58 0x20 … = 32 bytes
3Text string0x64 0x6e 0x6f 0x6e 0x65 = "none"
4Array0x81 …
5Map0xa3 … = 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

KeyNameEC2 (P-256)RSAOKP (Ed25519)
1kty231
3alg-7 (ES256)-257 (RS256)-8 (EdDSA)
-1crv / n1 (P-256)n (bytes)6 (Ed25519)
-2x / ex (32 bytes)e (usually 65537)x (32 bytes)
-3yy (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

  1. Read kty first (2 = EC2, 3 = RSA, 1 = OKP).
  2. Confirm alg is in the list the server accepts.
  3. For EC2, check crv = 1 (P-256) and that x and y are 32 bytes each.
  4. 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 decoder

Frequently 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

Read next