Error: secretOrPrivateKey must be an asymmetric key when using ES256
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- javascript, node.js, typescript
- Domain
- authentication, backend-api-design, security
Research direction
Reproduce the call at src/app.ts:151 using the issuer.getPrivateKey() value and the ES256 options shown. Trace the failure through node_modules/jsonwebtoken/sign.js:124, then compare the key value accepted by sign with the value passed to verify. Done means the supported behavior or required key format is established and covered by a focused regression test or documentation.
Written by the indexing model from the issue text.
Description
Description
I am unable to sign a jwt by using the private key associated to a Metamask wallet. Ideally I would like to sign a jwt for a verifiable credential by using the private key of the issuer of the credential:
const vcPayload = {
sub: sub.getDid(),
nbf: Math.floor(Date.now() / 1000),
vc: {
'@context': ['https://www.w3.org/2018/credentials/v1'],
type: ['VerifiableCredential'],
credentialSubject: {
degree: {
type: 'BachelorDegree',
name: 'Baccalauréat en musiques numériques'
}
}
}
}
const vcJwt = jwt.sign(vcPayload, issuer.getPrivateKey(), { algorithm: 'ES256' });
const decodedJwt = jwt.decode(vcJwt, { complete: true });
console.log(`Decoded VC: ${JSON.stringify(decodedJwt)}`);
const verifiedJwt = jwt.verify(vcJwt, issuer.getPublicKey(), { algorithms: ['ES256'] });
console.log(`Verified VC: ${JSON.stringify(JSON.stringify(verifiedJwt))}`);
The problem I am encountering is the following one:
Error: secretOrPrivateKey must be an asymmetric key when using ES256
at module.exports [as sign] (node_modules/jsonwebtoken/sign.js:124:22)
at main (src/app.ts:151:21)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {stack: 'Error: secretOrPrivateKey must be an asymmetr…ions (node:internal/process/task_queues:95:5)', message: 'secretOrPrivateKey must be an asymmetric key when using ES256'}
Environment
"jsonwebtoken": "9.0.0"
- Dominant language
- JavaScript
- Stars
- 18.2k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from auth0/node-jsonwebtoken
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
auth0/node-jsonwebtoken#1042 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
auth0/node-jsonwebtoken#1000 · 2 comments · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 65/100
auth0/node-jsonwebtoken#1046 ·
-
Difficulty 5/5 Over a week Newbie friendliness 10/100
auth0/node-jsonwebtoken#1034 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
auth0/node-jsonwebtoken#1032 ·
All issues in auth0/node-jsonwebtoken
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
antfu-collective/icones#398 ·
-
ECmail.com Open
Difficulty 1/5 Under an hour Newbie friendliness 90/100
wesbos/burner-email-providers#554 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
radiantearth/stac-browser#1023 ·
-
HMR stops working Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
components-web-app/docs#92 ·