This is demo runkit for creating JWE token using given asymmetric keys.
Lets create RS2048 key pair pragrammitically to use in this demo.
const jose = require('node-jose');
// Generate a new RSA key pair
// this is for convinienve of this demo, replace this with your key generation logic
async function createKeysForSigning() {
const keystore = jose.JWK.createKeyStore();
const props = {
use: 'sig',
alg: 'RSA-OAEP',
};
const createdKey = await keystore.generate("RSA", 2048, props)
const key = createdKey.toJSON();
// we are logging private key so we can use it in the decoding solution
const privateKeyPem = createdKey.toPEM(true);
console.log(privateKeyPem);
// set key options
key.use = "enc";
key.key_ops = ["encrypt", "verify", "wrap"];
// set the key to store store
const signKey = await jose.JWK.asKey(key);
return signKey;
}
Following function generates JWE token using given keys