Error: no importer for key when importing "pem" key
Error: no importer for key when importing "pem" key
应用程序按照 node-jose 2.0.0
上的说明导入 .pem
密钥。这是文档:
To import and existing Key from a PEM or DER:
// input is either a:
// * String serialization of a JSON JWK/(base64-encoded) PEM/(binary-encoded) DER
// * Buffer of a JSON JWK/(base64-encoded) PEM/(binary-encoded) DER
// form is either a:
// * "json" for a JSON stringified JWK
// * "private" for a DER encoded 'raw' private key
// * "pkcs8" for a DER encoded (unencrypted!) PKCS8 private key
// * "public" for a DER encoded SPKI public key (alternate to 'spki')
// * "spki" for a DER encoded SPKI public key
// * "pkix" for a DER encoded PKIX X.509 certificate
// * "x509" for a DER encoded PKIX X.509 certificate
// * "pem" for a PEM encoded of PKCS8 / SPKI / PKIX //<<=="pem"
keystore.add(input, form).
then(function(result) {
// {result} is a jose.JWK.Key
});
密钥已经以 .pem
形式生成,其内容存储在 nodejs 配置文件中,如下变量 process.env.josePrivateKey
:
-----BEGIN PRIVATE KEY-----
NC4CAQAwBQYcK2VwBCIEIIWUb0/MoKaBxQkmmPlHIGyPfDQb/U3D6jQ+gMUGtvpa
-----END PRIVATE KEY-----
这是将 pem
密钥添加到密钥库的代码:
const jose = require('node-jose');
let keystore = jose.JWK.createKeyStore();
let privkey = await keystore.add(process.env.josePrivateKey, "pem"); //<<==this code throws error
但是出现错误:
(node:11572) UnhandledPromiseRejectionWarning: Error: no importer for key
at JWKStore.value (C:\d\code\js\xyz\node_modules\node-jose\lib\jwk\keystore.js:305:21)
at initKeystore (C:\d\code\js\xyz\startup\accessstorageinfo.js:9:34) //<<==code as above
at Object.<anonymous> (C:\d\code\js\xyz\startup\accessstorageinfo.js:14:1)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (C:\d\code\js\xyz\server.js:13:1)
密钥导入这里缺少什么?
(截至 2021 年 3 月)node-jose
不支持以下密钥:Ed25519、Ed448、X25519 或 X448。它也不支持 secp256k1
EC 曲线。对于其中任何一个,它都会 return 您遇到的错误。因此它不支持 JWS 算法 EdDSA
或 ES256K
.
另一方面,https://github.com/panva/jose 在 Node.js 运行时支持以上所有内容。
应用程序按照 node-jose 2.0.0
上的说明导入 .pem
密钥。这是文档:
To import and existing Key from a PEM or DER:
// input is either a:
// * String serialization of a JSON JWK/(base64-encoded) PEM/(binary-encoded) DER
// * Buffer of a JSON JWK/(base64-encoded) PEM/(binary-encoded) DER
// form is either a:
// * "json" for a JSON stringified JWK
// * "private" for a DER encoded 'raw' private key
// * "pkcs8" for a DER encoded (unencrypted!) PKCS8 private key
// * "public" for a DER encoded SPKI public key (alternate to 'spki')
// * "spki" for a DER encoded SPKI public key
// * "pkix" for a DER encoded PKIX X.509 certificate
// * "x509" for a DER encoded PKIX X.509 certificate
// * "pem" for a PEM encoded of PKCS8 / SPKI / PKIX //<<=="pem"
keystore.add(input, form).
then(function(result) {
// {result} is a jose.JWK.Key
});
密钥已经以 .pem
形式生成,其内容存储在 nodejs 配置文件中,如下变量 process.env.josePrivateKey
:
-----BEGIN PRIVATE KEY-----
NC4CAQAwBQYcK2VwBCIEIIWUb0/MoKaBxQkmmPlHIGyPfDQb/U3D6jQ+gMUGtvpa
-----END PRIVATE KEY-----
这是将 pem
密钥添加到密钥库的代码:
const jose = require('node-jose');
let keystore = jose.JWK.createKeyStore();
let privkey = await keystore.add(process.env.josePrivateKey, "pem"); //<<==this code throws error
但是出现错误:
(node:11572) UnhandledPromiseRejectionWarning: Error: no importer for key
at JWKStore.value (C:\d\code\js\xyz\node_modules\node-jose\lib\jwk\keystore.js:305:21)
at initKeystore (C:\d\code\js\xyz\startup\accessstorageinfo.js:9:34) //<<==code as above
at Object.<anonymous> (C:\d\code\js\xyz\startup\accessstorageinfo.js:14:1)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (C:\d\code\js\xyz\server.js:13:1)
密钥导入这里缺少什么?
(截至 2021 年 3 月)node-jose
不支持以下密钥:Ed25519、Ed448、X25519 或 X448。它也不支持 secp256k1
EC 曲线。对于其中任何一个,它都会 return 您遇到的错误。因此它不支持 JWS 算法 EdDSA
或 ES256K
.
另一方面,https://github.com/panva/jose 在 Node.js 运行时支持以上所有内容。