I have to encrypt the payload using ES256 algorithm. Also have to use kid in JWK as described in below code. I am using the jose libraries for creating signature. Below is the code:
var jose = require("node-jose");
async function a1(){
try {
const keystore = [
{
kty: 'EC',
kid: '6d858102402dbbeb0f9bb711e3d13a1229684792db4940db0d0e71c08ca602e1',
use: 'sig',
alg:'ES256'
}
]
const ks = await jose.JWK.asKeyStore(keystore);
const rawKey = ks.get(keystore[0].kid)
const key = await jose.JWK.asKey(rawKey);
const payload =JSON.stringify({"sub": "1234567890", "name": "Eric D.", "role": "admin","iat": 1516239022});
const token =await jose.JWS.createSign({alg: "ES256", format: 'compact'}, key).update(payload, "utf8").final();
}catch (err) {
console.log(err);
}
}
a1();
But I am getting error:
unsupported algorithm.
Please let me know why is this issue coming.