Hello, I am attempting to create a JWT token using the internal utils provided.
However, I am faced with the error: x509: failed to parse private key (use ParsePKCS8PrivateKey instead for this key format)
let currentDate = Math.floor(new Date().getTime() / 1000);
let header = {
typ: "JWT",
alg: "ES256",
kid: "....",
...other
};
let payload = {
iss: ".....",
aud: "....",
iat: currentDate,
exp: currentDate + 60 * 59,
...other
};
let privateKey = `-----BEGIN PRIVATE KEY-----
.....
-----END PRIVATE KEY-----`;
let token = utils.jwt.encode("ES256", payload, privateKey, header);
Per the docs the key need to be an An ECDSA private key in PKCS#8 format.
which it is.
On my local machine using var jwt = require("jsonwebtoken");
it works perfectly fine.
Other variations I have tried:
1- loading the key from a package my_key.p8
2- base64 encoding the key
3- removing the \n characters