2

I used jsonwebtoken package in node.js to generate token. Everything is working fine if i use HS256 / HS384 / HS512 algorithm. But when i use other algorithm like RS256 / PS256 / ES256 it will throw an error. I like to know what i did wrong. Thanks in advance.

jwt.sign({ foo: 'bar' }, 'this is a secret key', { algorithm: 'RS256' }, function (err, token) {
          if (err) {
            console.log(err)
          }
          console.log(token);
        });

Error:

Error: error:0909006C:PEM routines:get_name:no start line
    at Sign.sign (internal/crypto/sig.js:84:29)
    at Object.sign (D:\Git\contact-node\node_modules\jwa\index.js:152:45)
    at jwsSign (D:\Git\contact-node\node_modules\jws\lib\sign-stream.js:32:24)
    at SignStream.sign (D:\Git\contact-node\node_modules\jws\lib\sign-stream.js:58:21)
    at SignStream.<anonymous> (D:\Git\contact-node\node_modules\jws\lib\sign-stream.js:46:12)
    at Object.onceWrapper (events.js:299:28)
    at DataStream.emit (events.js:210:5)
    at DataStream.<anonymous> (D:\Git\contact-node\node_modules\jws\lib\data-stream.js:32:12)
    at processTicksAndRejections (internal/process/task_queues.js:75:11) {
  library: 'PEM routines',
  function: 'get_name',
  reason: 'no start line',
  code: 'ERR_OSSL_PEM_NO_START_LINE'
}
1

1 Answer 1

2

Apparently, the algorithms RS256 and the others you specified are assymetric algorithms. You have to generate two different keys (public and private keys) and use the private key to encode and public to decode. So use the generated keypair. Refer How to create public and private key with openssl? to generate the keys. And HS256 is a symmetric algorithm, so it uses only one secret key.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.