What is the easiest way to convert a PKCS8 formatted EC Key string into a JWK using ECSDA?

I don’t care if it is the OpenSSL, Python or other ways.

The reason why I want to convert from PKCS8 string (with Elliptic Curve key) to JSON Web Key (JWK), so I can see the claims like kid, etc

I’ve tried using the eckles library.

var Eckles = require('eckles');
var pem = require('fs')
  .readFileSync('./node_modles/eckles/fixtures/privkey-ec-p256.sec1.pem', 'ascii');

Eckles.import({ pem: pem }).then(function (jwk) {
  console.log(jwk);
});

but the output only returns the kty, crv, d, x, y .. but not the kid claims.

  • 1

    The kid is JWK specific, the PKCS#8 format does not contain a kid, which is why none is exported.

    – 




  • Incidentally, the conversion PEM->JWK is also possible with the crypto module of NodesJS: crypto.createPrivateKey(<your PEM key>).export({format: 'jwk'}).

    – 

Leave a Comment