You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Using JWK as encoding format for public key in crypto.generateKeyPairSync() throws an error #39205
How often does it reproduce? Is there a required condition?
Everytime. If I change the public key encoding format to "pem" or "der" it dosen't throw an error. It seems like "jwk" is the only broken format.
What is the expected behavior?
Should probably look something like the output below. I used the keyObject.export() to create this output because as mentioned above, crypto.generateKeyPairSync() dosen't work at all with "jwk".
node:internal/crypto/keys:268
throw new ERR_INVALID_ARG_VALUE(optionName, formatStr);
^
TypeError [ERR_INVALID_ARG_VALUE]: The property 'options.publicKeyEncoding.format' is invalid. Received 'jwk'
at new NodeError (node:internal/errors:363:5)
at parseKeyFormat (node:internal/crypto/keys:268:9)
at parseKeyFormatAndType (node:internal/crypto/keys:304:18)
at parseKeyEncoding (node:internal/crypto/keys:332:7)
at parsePublicKeyEncoding (node:internal/crypto/keys:371:10)
at parseKeyEncoding (node:internal/crypto/keygen:125:9)
at createJob (node:internal/crypto/keygen:161:42)
at Object.generateKeyPairSync (node:internal/crypto/keygen:95:22)
at Object.<anonymous> (C:\Users\johannes.nydahl\Desktop\Playground\main.js:3:21)
at Module._compile (node:internal/modules/cjs/loader:1095:14) {
code: 'ERR_INVALID_ARG_VALUE'
}
Additional information
Tested on both node version v16.4.0 and v15.9.0 (v15.9.0 was when keyObject.export() first started to support "jwk" as format.
The combination { type: "spki", format: "jwk" } makes little sense. SPKI is a traditional cryptographic format, JWK is a new format that's incompatible with these older formats.
My cryptographic skills are lacking so I just picked "spki" because it was the only type that private EC keys supported according to the documentation. But from what I've tested, not using the "type" option at all throws the same error.
Activity
tniessen commentedon Jul 1, 2021
cc @nodejs/crypto (especially @panva @jasnell)
tniessen commentedon Jul 1, 2021
The combination
{ type: "spki", format: "jwk" }makes little sense. SPKI is a traditional cryptographic format, JWK is a new format that's incompatible with these older formats.johannesnydahl commentedon Jul 2, 2021
@tniessen
My cryptographic skills are lacking so I just picked "spki" because it was the only type that private EC keys supported according to the documentation. But from what I've tested, not using the "type" option at all throws the same error.
panva commentedon Jul 2, 2021
🤦♂️ i forgot about this interaction
A simple
{ format: 'jwk' }should work for the supported key types but currently doesn't.himself65 commentedon Jul 8, 2021
crypto: fix `generateKeyPair` with encoding 'jwk'
D4nte commentedon Jan 5, 2022
I believe the issue also exist on node 15 but was not fixed: https://github.com/D4nte/js-libp2p-crypto/runs/4438572378?check_suite_focus=true
Can the fix be backported to 15?
Cc @jasnell
panva commentedon Jan 5, 2022
@D4nte the fix was never meant to land on v15.x since it has reached End-Of-Life on 2021-06-01.
crypto: fix `generateKeyPair` with encoding 'jwk'