When writing code or testing, it’s useful to have valid examples of whatever you’re working with for sanity checks. I need some example JWTs with accompanying private JWK and couldn’t find any, so I minted a few. I’m posting them here in the hopes they’re useful to others, too.
These keys were created using a fresh RS256 key. No other keys have been created using this key. Because the private part of this key pair is public — it’s literally right below, in plain text — remember that these keys should only ever be used for sanity checking and testing. In particular, never use these keys for production use cases!
Private JWK
{
"kty": "RSA",
"n": "0Vu_V2XethHpt12qWfLnWtsp3KVH_vwm0-ZzZ0qLrDnGo2zSXpup6YrkaHVbKYtr8hwJfea5JMt0Hf0rsXiWvXHRG-GK5B5soEzMEQtHQq9pwppS77289bNgUlYSesigB3vbWWPK28zmKt9cENPRX_prlN8M-8LwdqjTBT7JRlisGGwN7_YOxdfc7Jp33ITigtBpAbCcnQmi1j5ES4LEch0Qen2cH13hl6A5NEKU40PN5_qgZf4apR8peDkkG8rwWqomRK-H4ANgBoS6xV4l9hKSF_S9aepvoPgV1TT7hYyhIdsZYEktqmH_YCCSHLTbeGb0e7Q0UU7ADn0Mj4chdw",
"e": "AQAB",
"kid": "maLPWma3RT9nbZoxyBdFMCaKuwnkAy7qX-psOyRmKec",
"d": "Xf8r5wERX7ymKxJOSEljb2sEHhFFRGoQwsXunXseP8rG8RwMTbblMDqQd4ftULdM1WyaJGFhUfBY55gCNJG4WEFQSgzXL7mrOsOQQbzHF10rhliEkSgmvUf2oLENZfxKwWFuJ_HCpDIYSzpymwmHMWj9QV9t9GFfVl9RM0Mv2jloZ438Feww2tZFU27VEkigXQjpwHLvk_KCe6I6nrIHVIeCLFqDh23m22UTb-MMtmADB-N9xpZJMF6pct9qKi2MjqRBhkfkDlk9p4_D9h2BkvNlm_MWBykcrNd84vKgrvEJkOj5BwO2w8jJzHvrF4YZwcohEKK5MfonymU4tnSkvQ",
"p": "2SoWlNnqefPZDpuB0XLncj14VrRg88_l2DKRmUnjDGWzEJSGvgRwcJ8Nc9uXTiDqJVZmGvKt5Pn2emNZJD2-Cmdpbu3Jbu7CEJRC0cG6Uecnvj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6EBFrmsvG-p6opd4acso6cMGBufHfqh3FRMXFuT4RaZ92nSmP_WS4lvwk4ueCgta09e6gD8E8cwHdPZBa1d7fV2TcHIyuha5vEofoAynY-9Pcy4Q
Dissecting a JWT
There are many great resources online for dissecting JWTs, so I won’t go into great detail here. The following dissection of the first JWT (via jwt.io) unpacks the token and shows the relationship between the JWT and the JWK:
In particular, note that the algorithm is RS256 (as previously stated), the claims are available, and the signature verified using the above JWK as the public/private keys.
Generating More JWTs
For reference, here is the Java code I used to generate these keys:
KeyPair pair = Jwts.SIG.RS256.keyPair().build();
RSAPublicKey pubKey = (RSAPublicKey) pair.getPublic();
RSAPrivateKey privateKey = (RSAPrivateKey) pair.getPrivate();
RsaPrivateJwk privateJwk = Jwks.builder().key(privateKey).idFromThumbprint().build();
RsaPublicJwk pubJwk = privateJwk.toPublicJwk();
byte[] utf8Bytes = new JacksonSerializer<>().serialize(privateJwk);
String jwkJson = new String(utf8Bytes, StandardCharsets.UTF_8);
System.out.println(jwkJson);
System.out.println(
Jwts.builder()
.id(UUID.randomUUID().toString())
.subject("alice")
.audience()
.add("everyone")
.and()
.claim("hello", "world")
.signWith(privateKey)
.compact());
System.out.println(
Jwts.builder()
.id(UUID.randomUUID().toString())
.subject("bob")
.audience()
.add("everyone")
.and()
.claim("hello", "world")
.signWith(privateKey)
.compact());
System.out.println(
Jwts.builder()
.id(UUID.randomUUID().toString())
.subject("charlie")
.audience()
.add("everyone")
.and()
.claim("hello", "world")
.signWith(privateKey)
.compact());
The Maven dependency GAVs are:
io.jsonwebtoken:jjwt-api:0.12.5
io.jsonwebtoken:jjwt-impl:0.12.5
io.jsonwebtoken:jjwt-jackson:0.12.5