JWT signing with private key & passphrase throws error
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 42/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- javascript, node.js
调研方向
使用 Node.js v12.20.0 重现该示例,然后沿着堆栈跟踪中显示的 jsonwebtoken/sign.js、jwa/index.js 和 jws/lib/sign-stream.js 追踪签名路径。当受密码短语保护的 PEM 私钥能够在不出现 key.key 类型错误的情况下签名 PS512 令牌,并且为此情况添加回归覆盖时,修复才算完成。
由索引模型根据 Issue 内容生成。
描述
Description
Signing jwt token with private key & passphrase results in error. Generated private key as below
ssh-keygen -t rsa -b 2048 -m PEM -f PS512.key and add passphrase
Reproduction
const jwt = require('jsonwebtoken');
const privateKey = `<copy & paste the generated private key here>`;
const token = jwt.sign(
{ test: 12 },
{ key: privateKey , passphrase: '...' }, {
algorithm: 'PS512'
});
console.log(token);
Error
internal/crypto/keys.js:288
throw new ERR_INVALID_ARG_TYPE(
^
TypeError [ERR_INVALID_ARG_TYPE]: The "key.key" property must be of type string or an instance of Buffer, TypedArray, DataView, or KeyObject. Received an instance of Object
at prepareAsymmetricKey (internal/crypto/keys.js:288:13)
at preparePrivateKey (internal/crypto/keys.js:308:10)
at Sign.sign (internal/crypto/sig.js:94:46)
at Object.sign (jwt-playground/node_modules/jwa/index.js:174:45)
at Object.jwsSign [as sign] (jwt-playground/node_modules/jws/lib/sign-stream.js:32:24)
at Object.module.exports [as sign] (jwt-playground/node_modules/jsonwebtoken/sign.js:204:16)
at Object.<anonymous> (jwt-playground/pem-format-passphrase/jwt-pem-formar-passphrase.js:75:19)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32) {
code: 'ERR_INVALID_ARG_TYPE'
}
Environment
- Version of the library used: 8.5.1
- Version of the Node.js: v12.20.0
- OS: macOS Monterey - 12.6
- 主要语言
- JavaScript
- 星标
- 18.2k
- 派生
- 1.3k
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
auth0/node-jsonwebtoken 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
auth0/node-jsonwebtoken#1042 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 84/100
auth0/node-jsonwebtoken#1000 · 2 条评论 · 1 个 reaction ·
-
难度 4/5 3-5 天 新手友好度 65/100
auth0/node-jsonwebtoken#1046 ·
-
难度 5/5 一周以上 新手友好度 10/100
auth0/node-jsonwebtoken#1034 ·
-
难度 3/5 1-2 天 新手友好度 48/100
auth0/node-jsonwebtoken#1032 ·
查看 auth0/node-jsonwebtoken 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
-
area-deployment area-integrations triage:bot-seen
难度 2/5 半天 新手友好度 86/100
-
Issue-Bug
难度 2/5 1-3 小时 新手友好度 68/100
sugarlabs/musicblocks#8924 ·
-
难度 1/5 1 小时以内 新手友好度 90/100
ArduPilot/ardupilot_wiki#8088 ·
-
[BUG] createTool tools cannot be registered with Mastra when exactOptionalPropertyTypes is enabled 未关闭customer-eng status: needs triage
难度 2/5 1-3 小时 新手友好度 84/100