How header JSON, payload claims, and signing key material become a compact three-part JWT
Issuing a JSON Web Token begins with two JSON objects you control. The header states typ JWT and an alg that names the signing primitive for the third segment. The payload holds registered and private claims such as sub, exp, and iat. Each object is serialized to compact UTF-8 JSON without insignificant whitespace, then each byte string is spelled in Base64URL, the URL-safe alphabet described on Base64 where plus becomes minus, slash becomes underscore, and padding equals signs are usually dropped. The compact token concatenates those two spellings with a single dot between them before any cryptographic step runs.
Signing does not encrypt the middle segment. Anyone who receives the finished string can Base64URL-decode the payload and read claim values in plain JSON. What signing adds is integrity: the third segment proves that whoever held the signing secret or private key approved that exact header and payload pair at issuance time. The signing input defined in JOSE is always the UTF-8 bytes of headerBase64URL, one dot, and payloadBase64URL exactly as they will appear in the first two segments of the output. Hash-then-sign or HMAC families consume that string; they never sign pretty-printed JSON or raw claim objects directly.
Symmetric HS256, HS384, and HS512 apply HMAC with a shared secret both issuer and verifier must guard. Asymmetric RS256 through RS512 sign with RSA PKCS#1 using a private key; PS256 through PS512 use RSA-PSS; ES256 through ES512 use ECDSA on named curves with a private key whose public half appears in SPKI PEM on RSA cipher. Pick alg before you paste key material so the header matches the math. After you emit the compact string, confirm structure and signature on JWT debugger. NumericDate claims such as exp and iat must be whole seconds since the Unix epoch, which you can line up on timestamp.
How Base64URL spelling, the dot-separated signing input, alg families, and claims fit issuance
Why the JOSE signing input always uses Base64URL segments joined by a dot before any signature bytes
- The input string is header segment text, ASCII dot, payload segment text. It must match the first two segments of the token byte for byte.
- Re-encoding the same JSON with different key order or spacing changes Base64URL output and therefore changes the signature even when claims mean the same thing.
- Libraries compute the third segment from that dotted string only. Pretty JSON in an editor is a drafting view, not the wire form that HMAC or RSA consumes.
Why the header alg field must name the same algorithm your signing key is built to use at issue time
- typ JWT tells parsers the object is a JSON Web Token. alg tells verifiers which primitive validates the third segment.
- HS family means HMAC with SHA-256, SHA-384, or SHA-512 and a shared secret string or byte key both sides must protect.
- RS and PS mean RSA with PKCS#1 or PSS padding and a private PEM at issuance. ES means ECDSA on a named curve. Mismatch between alg and key type yields tokens nobody can verify.
Why exp and iat claims in the payload should be NumericDate seconds when you set session lifetime
- exp is seconds after the Unix epoch when verifiers should stop accepting the token unless local policy overrides expiry.
- iat records issuance instant in the same second units. Optional nbf forbids use before a start second with the same NumericDate shape.
- Wall clocks in milliseconds pasted into exp look decades in the future when parsers treat them as seconds. Convert civil time on timestamp before you embed exp or nbf.
Why HS256 shared secrets and RS PS ES private PEM keys are never interchangeable signing inputs
- HS256, HS384, and HS512 need the symmetric secret bytes the verifier will later use for HMAC comparison, not a public certificate.
- RS256 through ES512 need a PKCS#8 or traditional PEM private key for signing. Verifiers hold only the SPKI public PEM, never the private half.
- Choosing alg first routes you to the correct key field and keeps the emitted header honest. Compare HS versus RS tradeoffs in the FAQ before you standardize on one family.
Where issuance looks finished but verifiers or expiry checks still fail
A freshly signed token whose third segment never validates on the API that should trust the issuer
The compact string can look well formed while verification fails. HS family tokens require the same shared secret at sign and verify time; a staging secret on the encoder and production secret on the API causes silent mismatch. RS, PS, and ES tokens require the public PEM that pairs with the private key used here, not an old rotation or a certificate with the wrong SPKI extract. After signing, paste the output into JWT debugger with the verify-side key to catch key drift before deployment.
An exp claim set from a thirteen-digit millisecond clock that makes sessions appear immortal
RFC 7519 NumericDate uses seconds, not milliseconds. Embedding a JavaScript Date.now value without scaling tells parsers the token stays valid for an absurd horizon. Set iat and exp using second counts you can read beside civil time on timestamp. Re-sign after correcting units so the header and payload Base64URL segments change and the signature matches the fixed claims.
A header that lists alg none or omits a real signature when the resource server expects integrity
Unsigned tokens may help local experiments but production APIs must reject alg none. This encoder requires a supported alg and real signing material for the third segment. If you inherited claims from a debugger session, reissue with HS, RS, PS, or ES and a proper key rather than shipping a payload anyone could rewrite. Confirm the three segments on JWT debugger after each issuance change.