Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any util in jose to convert key from PEM to JWK for Ed25519?

Tags:

jose

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.

like image 579
user938363 Avatar asked Oct 21 '25 13:10

user938363


1 Answers

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.