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

Can't change algorithm

Open
#803 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
30/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
javascript, node.js
Domain
backend, security

Research direction

Run the supplied jwt.sign reproduction first, then trace the call through node_modules/jsonwebtoken/sign.js, node_modules/jws/lib/sign-stream.js, and node_modules/jwa/index.js. Compare the ES256 and README RS256 cases, including the supplied key values. Done means identifying whether the failure is in algorithm handling or PEM input and documenting or fixing the reproducible cause.

Written by the indexing model from the issue text.

Description

Description

Trying to use ES256 by passing algorithm: 'ES256' into options and getting:

Error: error:0908F066:PEM routines:get_header_and_data:bad end line
    at Sign.sign (node:internal/crypto/sig:131:29)
    at sign (/Users/liamdoyle/Developer/limegorilla/apple-jwt-node-test/node_modules/jwa/index.js:152:45)
    at Object.sign (/Users/liamdoyle/Developer/limegorilla/apple-jwt-node-test/node_modules/jwa/index.js:200:27)
    at Object.jwsSign [as sign] (/Users/liamdoyle/Developer/limegorilla/apple-jwt-node-test/node_modules/jws/lib/sign-stream.js:32:24)
    at Object.module.exports [as sign] (/Users/liamdoyle/Developer/limegorilla/apple-jwt-node-test/node_modules/jsonwebtoken/sign.js:204:16)
    at file:///Users/liamdoyle/Developer/limegorilla/apple-jwt-node-test/app.js:22:26
    at ModuleJob.run (node:internal/modules/esm/module_job:185:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:281:24)
    at async loadESM (node:internal/process/esm_loader:88:5) {
  library: 'PEM routines',
  function: 'get_header_and_data',
  reason: 'bad end line',
  code: 'ERR_OSSL_PEM_BAD_END_LINE'
Reproduction
let generatedToken = jwt.sign({
    iss: teamId, // Required by Apple
    exp: Math.floor(Date.now() / 1000) + (60 * 60),
}, token, {
    algorithm: 'ES256',
    header: {
        kid: keyId
    }
});

Also tried using this example from the readme:

jwt.sign({ foo: 'bar' }, privateKey, { algorithm: 'RS256' });

Same error.

Environment

Node 16.3
jsonwebtoken 8.5.1
macOS 12

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.