Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Error: secretOrPrivateKey must be an asymmetric key when using ES256

Open
#898 13 comments 3 reactions 0 assignees View on GitHub

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

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from auth0/node-jsonwebtoken

All issues in auth0/node-jsonwebtoken

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.