包含jsonwebtoken sign()方法的选项时出现错误

时间:2019-03-18 19:39:02

标签: node.js jwt

我正在节点后端使用jsonwebtoken库对认证令牌进行签名。我已经可以在不包含选项的情况下正常运行了,它能够成功检索响应。如果包含这些选项,则会出现以下错误:

Error: error:0906D06C:PEM routines:PEM_read_bio:no start line
    at Sign.sign (crypto.js:331:26)
    at Object.sign (/Users/jaai/Desktop/ProtoBank/ProtoBankBack/node_modules/jwa/index.js:152:45)
    at Object.jwsSign [as sign] (/Users/jaai/Desktop/ProtoBank/ProtoBankBack/node_modules/jws/lib/sign-stream.js:32:24)
    at Object.module.exports [as sign] (/Users/jaai/Desktop/ProtoBank/ProtoBankBack/node_modules/jsonwebtoken/sign.js:204:16)
    at router.post (/Users/jaai/Desktop/ProtoBank/ProtoBankBack/routes/api.js:19:36)
    at Layer.handle [as handle_request] (/Users/jaai/Desktop/ProtoBank/ProtoBankBack/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/jaai/Desktop/ProtoBank/ProtoBankBack/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/Users/jaai/Desktop/ProtoBank/ProtoBankBack/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/Users/jaai/Desktop/ProtoBank/ProtoBankBack/node_modules/express/lib/router/layer.js:95:5)
    at /Users/jaai/Desktop/ProtoBank/ProtoBankBack/node_modules/express/lib/router/index.js:281:22

这是我创建令牌的方式:

const jwtBearerToken = jwt.sign(userData, RSA_PRIVATE_KEY,
    {
        // works if I exclude this part
        algorithm: 'RS256',
        expiresIn: '1h'
    }
)

res.status(200).send({ signed_user: userData, token: jwtBearerToken });

0 个答案:

没有答案