Signing keys and JWKS
Create an RSA key pair and publish the public half so Hub can verify your requests.
Hub has no client secret. Instead you sign your requests with a private key, and Hub checks the signature using a public key you publish.
This page shows you how to set that up.
How it works
- You create an RSA key pair
- You keep the private key secret and sign requests with it
- You publish the public key at a URL Hub can reach
- Hub fetches it and verifies your signature
Your private key never leaves your server. The public key can't be used to forge requests, so publishing it is safe.
Key requirements
| Attribute | Value |
|---|---|
| Key type | RSA |
| Size | 2048 bits |
| Algorithm | RS256 |
| Use | sig (signing, not encryption) |
Step 1 — Create the key pair
Use your organization's approved methodThe example below uses
openssl, so you can see each step. In practice, create the key with whatever method your organization has approved — for example a cryptography library in your application's language, your cloud provider's key management service, or a hardware security module (HSM). Any method works, as long as the key meets the requirements above.
# Private key - keep this secret
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out hub-private.pem
# Public key
openssl rsa -in hub-private.pem -pubout -out hub-public.pem
Store the private key the way you store any other production secret — a secrets manager or HSM. Never commit it, never log it, never send it to Interac.
Step 2 — Convert to JWK format
Your public key needs to be published as a JSON Web Key, not PEM. Each example reads hub-public.pem from Step 1 and writes jwks.json, ready to publish in Step 3.
import json
from jwcrypto import jwk # pip install jwcrypto
with open("hub-public.pem", "rb") as f:
key = jwk.JWK.from_pem(f.read())
public_key = key.export_public(as_dict=True)
public_key.update(use="sig", alg="RS256", kid=key.thumbprint())
with open("jwks.json", "w") as f:
json.dump({"keys": [public_key]}, f, indent=2)import { readFile, writeFile } from "node:fs/promises";
import { importSPKI, exportJWK, calculateJwkThumbprint } from "jose"; // npm install jose
const key = await importSPKI(await readFile("hub-public.pem", "utf8"), "RS256", { extractable: true });
const publicJwk = await exportJWK(key);
Object.assign(publicJwk, { use: "sig", alg: "RS256", kid: await calculateJwkThumbprint(publicJwk) });
await writeFile("jwks.json", JSON.stringify({ keys: [publicJwk] }, null, 2));//DEPS com.nimbusds:nimbus-jose-jwt:10.10
//DEPS org.bouncycastle:bcpkix-jdk18on:1.87
import com.nimbusds.jose.JWSAlgorithm;
import com.nimbusds.jose.jwk.JWK;
import com.nimbusds.jose.jwk.JWKSet;
import com.nimbusds.jose.jwk.KeyUse;
import com.nimbusds.jose.jwk.RSAKey;
import java.nio.file.Files;
import java.nio.file.Path;
public class ToJwks {
public static void main(String[] args) throws Exception {
RSAKey key = JWK.parseFromPEMEncodedObjects(Files.readString(Path.of("hub-public.pem"))).toRSAKey();
RSAKey publicKey = new RSAKey.Builder(key)
.keyUse(KeyUse.SIGNATURE)
.algorithm(JWSAlgorithm.RS256)
.keyIDFromThumbprint()
.build();
Files.writeString(Path.of("jwks.json"), new JWKSet(publicKey).toString());
}
}#:package [email protected]
#:property PublishAot=false
using System.Security.Cryptography;
using System.Text.Json;
using Microsoft.IdentityModel.Tokens;
var rsa = RSA.Create();
rsa.ImportFromPem(File.ReadAllText("hub-public.pem"));
var jwk = JsonWebKeyConverter.ConvertFromRSASecurityKey(new RsaSecurityKey(rsa.ExportParameters(false)));
var publicKey = new { kty = "RSA", n = jwk.N, e = jwk.E, use = "sig", alg = "RS256", kid = Base64UrlEncoder.Encode(jwk.ComputeJwkThumbprint()) };
File.WriteAllText("jwks.json", JsonSerializer.Serialize(new { keys = new[] { publicKey } }, new JsonSerializerOptions { WriteIndented = true }));The kid is the key's thumbprint, a stable ID calculated from the key itself, so all four examples produce the same kid for the same key.
Prefer to create the key in code instead? The Create your signing key and JWKS recipe for each language does Steps 1 and 2 in one go.
Each key in the result has these properties:
{
"kty": "RSA",
"use": "sig",
"alg": "RS256",
"kid": "cIlDeR8D4RexrZmUdKhBxMsD2bMX4l87_5JrARh4VIU",
"n": "...",
"e": "AQAB"
}| Property | Meaning |
|---|---|
kty | Key type — RSA |
use | sig |
alg | RS256 |
kid | Key ID — a unique name for this key |
n, e | The key material |
kidis required. You put the same value in the header of every JWT you sign, and it's how Hub knows which key to check against. Without it, verification fails.
Step 3 — Publish it
Host a JWKS document at an HTTPS URL. It's a JSON object with a keys array:
{
"keys": [
{
"kty": "RSA",
"use": "sig",
"alg": "RS256",
"kid": "cIlDeR8D4RexrZmUdKhBxMsD2bMX4l87_5JrARh4VIU",
"n": "...",
"e": "AQAB"
}
]
}Requirements:
- HTTPS, publicly reachable from the internet
- Not behind a VPN, firewall or IP allowlist
- Returns
application/json - Stable — Hub fetches it when verifying requests
A common location is https://your-domain.com/.well-known/jwks.json, but any HTTPS URL works.
Reachable from the internet means reachable by Hub, not just by you. A URL that resolves on your corporate network but not publicly is the most common onboarding failure. Test it from a device outside your network.
Step 4 — Give the URL to your representative
You provide the URL, not the key. Hub fetches the key from it.
Using the key
You sign two things with the private key:
Both need kid in the JOSE header:
{
"alg": "RS256",
"kid": "cIlDeR8D4RexrZmUdKhBxMsD2bMX4l87_5JrARh4VIU"
}
Theaudvalue is different between those two. Using the wrong one is the most common cause of a rejected signature. See Troubleshooting.
Rotating keys
A JWKS document can hold more than one key, which is what makes rotation safe:
- Generate a new pair with a new
kid - Add the new public key to your JWKS, keeping the old one
- Start signing with the new private key
- Once nothing is signing with the old key, remove it
Because every JWT names its kid, both keys work during the overlap. Don't remove the old key immediately.
Common mistakes
| Problem | Cause |
|---|---|
invalid_client | kid missing from the JWT header, or not matching any key in your JWKS |
| Works locally, fails in production | JWKS URL not reachable from the internet |
| Signature rejected after rotation | Old key removed too soon, or kid not updated |
| Audience error | Wrong aud for the call being made |
| Intermittent failures | JWKS URL is slow or unreliable |
Checking your work
# Should return JSON containing your key
curl https://your-domain.com/.well-known/jwks.jsonConfirm it has kty, use, alg and kid, and that the kid matches what you put in your JWT headers.
Next
Updated 3 days ago