Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

JWT signing with private key & passphrase throws error

オープン
#860 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
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 はありません

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

auth0/node-jsonwebtoken のほかの issue

auth0/node-jsonwebtoken の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。