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

Error: secretOrPrivateKey must be an asymmetric key when using ES256

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

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

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ

Hướng nghiên cứu

Tái hiện lệnh gọi tại src/app.ts:151 bằng giá trị issuer.getPrivateKey() và các tùy chọn ES256 được hiển thị. Theo dõi lỗi qua node_modules/jsonwebtoken/sign.js:124, sau đó so sánh giá trị khóa được sign chấp nhận với giá trị được truyền vào verify. Hoàn tất khi hành vi được hỗ trợ hoặc định dạng khóa bắt buộc đã được xác lập và được bao phủ bởi một regression test tập trung hoặc tài liệu.

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

Mô tả

Description

I am unable to sign a jwt by using the private key associated to a Metamask wallet. Ideally I would like to sign a jwt for a verifiable credential by using the private key of the issuer of the credential:

const vcPayload = {
  sub: sub.getDid(),
  nbf: Math.floor(Date.now() / 1000),
  vc: {
    '@context': ['https://www.w3.org/2018/credentials/v1'],
    type: ['VerifiableCredential'],
    credentialSubject: {
      degree: {
        type: 'BachelorDegree',
        name: 'Baccalauréat en musiques numériques'
      }
    }
  }
}

const vcJwt = jwt.sign(vcPayload, issuer.getPrivateKey(), { algorithm: 'ES256' });

const decodedJwt = jwt.decode(vcJwt, { complete: true });
console.log(`Decoded VC: ${JSON.stringify(decodedJwt)}`);

const verifiedJwt = jwt.verify(vcJwt, issuer.getPublicKey(), { algorithms: ['ES256'] });
console.log(`Verified VC: ${JSON.stringify(JSON.stringify(verifiedJwt))}`);

The problem I am encountering is the following one:

Error: secretOrPrivateKey must be an asymmetric key when using ES256
    at module.exports [as sign] (node_modules/jsonwebtoken/sign.js:124:22)
    at main (src/app.ts:151:21)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {stack: 'Error: secretOrPrivateKey must be an asymmetr…ions (node:internal/process/task_queues:95:5)', message: 'secretOrPrivateKey must be an asymmetric key when using ES256'}
Environment

"jsonwebtoken": "9.0.0"

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.