3

An Ed25519 PEM key pair was generated as below:

-----BEGIN PRIVATE KEY-----
NC4CAQAwBQYcK2VwBCIEIIWUb0/MoKaBxQkmmPlHIGyPfDQb/U3D6jQ+gMUGtvpa
-----END PRIVATE KEY-----

-----BEGIN PUBLIC KEY-----
NCowBQYDK2VwAyEAWFnlEbTVgD4TilnSzyDmZK16dm1IeQURtHFcLhSwmDo=
-----END PUBLIC KEY-----

In jose 3.11.1, the parseJwk, taking JWK input, is used to generate keys used in signing and verification. Is there utility in jose converting PEM key to JWK used in paseseJwk or with a 3rd party utility? I didn't find one for nodejs project.

user938363
  • 9,990
  • 38
  • 137
  • 303

1 Answers1

6

To get a KeyObject you don't need your keys in JWK format. It works with node's KeyObject instances. So you can easily do

const { createPublicKey, createPrivateKey } = require('crypto')

const publicKey = createPublicKey(pemPublicKey)
const privateKey = createPrivateKey(pemPrivateKey)

This is documented in the KeyLike interface the library uses in its docs.