I'm trying to sign some data with a JWK i've been provided with.
So far i've tried to do this with jwt.io, the header is
{ "alg" : "RS256", "typ" : "JWT" }
and the payload is
{ "iss" : "4@john" }
Now to sign this I need a public and a private key. I've been told to extract these from the JWK provided, but i only seem to be able to extract a public key from this.
I've used jwk-to-pem but when provided with the JWK it only puts out the public key. But to sign with RS256 i need a public and a private key, i thought the private key is embedded into the JWK but i can't seem to extract it.
So my question is, how to extract the public AND private key from the JWK?
The JWK looks like this:
"ServicePrincipalKey": {
"k": null,
"kid": "urn:service:john:doe:4",
"kty": "RSA",
"use": null,
"n": "rT-...skQ",
"e": "A...B",
"x5t": null,
"d": "CP9...bsQ",
"p": "7dG...PDk",
"q": "un4...oxk",
"dp": "HdF...m4Xk",
"dq": "XGN...PMk",
"qi": "0es...UDI",
"nbf": "0001-01-01T00:00:00",
"exp": "0001-01-01T00:00:00"
}
Found the answer for jwk-to-pem. There is an option to generate a private and public key.
on runkit i executed the following code:
var jwkToPem = require("jwk-to-pem")
var jwk = {
"k": null,
"kid": "urn:service:john:doe:4",
"kty": "RSA",
"use": null,
"n": "rT-...skQ",
"e": "A...B",
"x5t": null,
"d": "CP9...bsQ",
"p": "7dG...PDk",
"q": "un4...oxk",
"dp": "HdF...m4Xk",
"dq": "XGN...PMk",
"qi": "0es...UDI",
"nbf": "0001-01-01T00:00:00",
"exp": "0001-01-01T00:00:00"
}
var publicPEM = jwkToPem(jwk);
console.log(publicPEM);
var options = {"private" : true} //important this will set jwkToPem to output the private key
var privatePEM = jwkToPem(jwk, options);
console.log(privatePEM);
This outputs a public and a private key into the console.
Now by filling in these public and private keys into jwt.io i was able to generate a JWT
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With