Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

JWT signing with private key & passphrase throws error

Aperta
#860 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
42/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
javascript, node.js

Direzione di ricerca

Riproduci l’esempio con Node.js v12.20.0, quindi traccia il percorso di firma attraverso jsonwebtoken/sign.js, jwa/index.js e jws/lib/sign-stream.js mostrati nello stack trace. La correzione è completa quando una chiave privata PEM protetta da passphrase può firmare un token PS512 senza l’errore di tipo key.key, con una copertura di regressione per questo caso.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
JavaScript
Stelle
18.2k
Fork
1.3k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di auth0/node-jsonwebtoken

Tutte le issue di auth0/node-jsonwebtoken

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.