【发布时间】:2020-11-04 13:24:59
【问题描述】:
我使用 node.js 中的 jsonwebtoken 包来生成令牌。如果我使用 HS256 / HS384 / HS512 算法,一切正常。但是当我使用像RS256/PS256/ES256这样的其他算法时,它会抛出一个错误。我想知道我做错了什么。提前致谢。
jwt.sign({ foo: 'bar' }, 'this is a secret key', { algorithm: 'RS256' }, function (err, token) {
if (err) {
console.log(err)
}
console.log(token);
});
错误:
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'
}
【问题讨论】:
-
尝试在 github 上阅读这篇文章 - github.com/auth0/node-jsonwebtoken/issues/642
标签: javascript node.js authentication jwt token