One key, five notations: raw, hex, Base64url, JWK, PEM
In one line: How a single 32-byte key becomes hex, Base64url, JWK, PKCS#8 PEM and SPKI PEM, and which form belongs where.
You copy a key and every library wants a different shape: 64 hex characters here, 43 Base64url characters there, several lines of PEM somewhere else. Once you hold on to the fact that it is one key with several notations, the confusion collapses.
1. Raw 32 bytes is the origin
Ed25519 and X25519 private and public keys are all 32 bytes. Every other format wraps those 32 bytes.
seed (32 bytes) = 9d61b19d…1cae7f60 public key (32 bytes) = d75a9801…f707511a
2. Hex and Base64url
| Notation | Length | Where it appears |
|---|---|---|
| Hex (lowercase) | 64 chars | Test vectors, debug logs, documentation |
| Base64url (no padding) | 43 chars | JOSE, URLs, cookies, config files |
Base64url replaces + with -, / with _ and drops = padding. The same 32 bytes are 64 characters in hex and 43 in Base64url, so the length alone usually tells you which one you have.
3. JWK: a key inside JSON
{
"kty": "OKP",
"crv": "Ed25519",
"x": "…public key as Base64url…",
"d": "…seed as Base64url…"
}
OKP (Octet Key Pair) is the JWK type RFC 8037 defines for Ed25519 and X25519. x is the public key, d the private key, both Base64url. With d it is a private JWK; without it, a public one. It is the least error-prone way to move a key across the web — but never leave a JSON object containing d in a log.
4. PEM and DER: the key in a structure
PEM is DER wrapped in Base64, broken into 64-character lines with a header and footer. For Ed25519 the structures are fixed.
| Format | DER length | Contents |
|---|---|---|
| PKCS#8 (private) | 48 bytes | version, algorithm OID 1.3.101.112, seed |
| SPKI (public) | 44 bytes | algorithm OID, public key |
| X25519 OID | — | 1.3.101.110 |
Because the PEM body is just that DER in Base64, removing the header line and decoding gives you 48 bytes (or 44) whose last 32 bytes are the key itself.
Watch out: private and public PEM use different header lines. One says PRIVATE KEY, the other PUBLIC KEY, and a library rejects the wrong one immediately. This page deliberately never prints that header string in full, so that copy-and-paste does not become an accident.
5. Fingerprints
When comparing keys is awkward, compare fingerprints. Ed25519Lab shows two.
- Raw fingerprint — SHA-256 over the 32-byte public key. Simple enough to match against other tools.
- SPKI fingerprint — SHA-256 over the whole SPKI DER, the same family as certificate and SSH key fingerprints.
The two differ. If a document just says "SHA-256 fingerprint", find out what was hashed.
6. Where conversions break
- Mixing standard Base64 and Base64url — leftover
+or/breaks in URLs. - Line breaks and spaces — losing them from a PEM body breaks decoding.
- Padding — some libraries still want the
=in Base64url. - Case — hex is conventionally lowercase.
Panel ① shows all five forms of the same 32 bytes at once, so you can compare the conversion by eye.
Making a key yourself shows the format differences immediately.
Open Ed25519LabFrequently asked questions
What are d and x in a JWK?
x is the public key and d the private key (seed), both Base64url. A JWK without d can verify but cannot sign.
When do I use PKCS#8 versus SPKI?
PKCS#8 holds a private key and is used where signing happens; SPKI holds a public key and is used for verification and certificates.
References
- RFC 5958 — Asymmetric Key Packages (PKCS#8)
- RFC 5280 — Internet X.509 Public Key Infrastructure
- RFC 7517 — JSON Web Key (JWK)
- RFC 8037 — CFRG Elliptic Curve Diffie-Hellman (ECDH) and Signatures in JOSE
Read next
- Ed25519 and X25519: one curve, two jobsWhat each of the two Curve25519 algorithms does, and why a key made from the same seed is not interchangeable between them.
- Ed25519 signing and verification, step by stepFollow the RFC 8032 signing procedure to see why the signature is deterministic and why verification fails on a single changed bit.
- X25519 shared secrets and why HKDF is not optionalHow X25519 produces a 32-byte shared secret, how to check both sides agree, and how HKDF-SHA256 derives purpose-specific keys.