Skip to content

Commit

Permalink
ECDSA: Output keys as JSONWebKeySet instead of two JWK
Browse files Browse the repository at this point in the history
  • Loading branch information
cplussharp committed Apr 14, 2024
1 parent 1fbc7e0 commit 7e7195c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/core/operations/GenerateECDSAKeyPair.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,21 @@ class GenerateECDSAKeyPair extends Operation {
let result;
switch (outputFormat) {
case "PEM":
pubKey = r.KEYUTIL.getPEM(keyPair.pubKeyObj);
privKey = r.KEYUTIL.getPEM(keyPair.prvKeyObj, "PKCS8PRV");
pubKey = r.KEYUTIL.getPEM(keyPair.pubKeyObj).replace(/\r/g, "");
privKey = r.KEYUTIL.getPEM(keyPair.prvKeyObj, "PKCS8PRV").replace(/\r/g, "");
result = pubKey + "\n" + privKey;
break;
case "DER":
result = keyPair.prvKeyObj.prvKeyHex;
break;
case "JWK":
pubKey = JSON.stringify(r.KEYUTIL.getJWKFromKey(keyPair.pubKeyObj));
privKey = JSON.stringify(r.KEYUTIL.getJWKFromKey(keyPair.prvKeyObj));
result = pubKey + "\n\n" + privKey;
pubKey = r.KEYUTIL.getJWKFromKey(keyPair.pubKeyObj);
pubKey.key_ops = ["verify"]; // eslint-disable-line camelcase
pubKey.kid = "PublicKey";
privKey = r.KEYUTIL.getJWKFromKey(keyPair.prvKeyObj);
privKey.key_ops = ["sign"]; // eslint-disable-line camelcase
privKey.kid = "PrivateKey";
result = JSON.stringify({keys: [privKey, pubKey]}, null, 4);
break;
}

Expand Down

0 comments on commit 7e7195c

Please sign in to comment.