Keys
Make, store, convert and rotate the keys that sign and encrypt your tokens, as JSON Web Keys.
Every token starts with a key, and there are two kinds. A secret is one key that both sides share, like the single key to a padlock: whoever holds it can sign and verify, or lock and unlock. A key pair is two keys that belong together. The private key signs or decrypts, and the public key verifies or encrypts. You keep the private key on your server and never hand it out; the public key you can give to anyone, which is how other services check your tokens without being able to make them. Concepts explains the vocabulary.
unjwt writes keys as JSON Web Keys (RFC 7517): plain JSON objects you can store in a secret manager, publish, and pass straight to sign(), verify(), encrypt() and decrypt(). A public ES256 key looks like this:
{
"kty": "EC",
"crv": "P-256",
"x": "cbCcIXJKSdiE8TGTgXgwNAf5PERuCJGMTGlRnj78Lqw",
"y": "bcMypp7pabIplm3uG1IeBFOt-8WiHFZbneJiHcrEfVA",
"alg": "ES256",
"kid": "2026-10"
}kty says what kind of key it is, alg the one algorithm it is for, and kid its name. The private half is the same object plus a d member. Every function on these pages comes from unjwt/jwk.
kty | What it is | Algorithms |
|---|---|---|
oct | A secret | HS*, A*KW, A*GCMKW, A*GCM, A*CBC-HS* |
RSA | An RSA key pair | RS*, PS*, RSA-OAEP* |
EC | An elliptic-curve key pair (P-256, -384, -521) | ES*, ECDH-ES* |
OKP | An Ed25519 or X25519 key pair | Ed25519, EdDSA, ECDH-ES* |
Generate keys
Make a secret or a key pair for any algorithm, and store it.
Import and export keys
Move between JWKs, CryptoKey objects and raw bytes, and name a key by its thumbprint.
Use PEM keys
Read the -----BEGIN …----- files OpenSSL and cloud consoles hand you.
Wrap and unwrap keys
Store a key encrypted under another key.
Derive keys from a password
Turn a passphrase into an encryption key with PBES2.
Use a JWK Set
Hold several keys, let the token pick one, and rotate without downtime.
The key cache
When imported keys are reused, and how to replace or reset that.