Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

JWT signing with private key & passphrase throws error

Đang mở
#860 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
42/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
javascript, node.js
Lĩnh vực
authentication, security

Hướng nghiên cứu

Tái hiện ví dụ bằng Node.js v12.20.0, sau đó lần theo đường dẫn ký qua jsonwebtoken/sign.js, jwa/index.js và jws/lib/sign-stream.js được hiển thị trong stack trace. Bản sửa được hoàn tất khi một khóa riêng PEM được bảo vệ bằng passphrase có thể ký token PS512 mà không gặp lỗi kiểu key.key, kèm theo kiểm thử hồi quy cho trường hợp này.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
JavaScript
Star
18.2k
Fork
1.3k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của auth0/node-jsonwebtoken

Tất cả issue của auth0/node-jsonwebtoken

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.