Skip to content

how to generate pair of keys? #39

Locked Answered by panva
Alexsey asked this question in Q&A
Discussion options

You must be logged in to vote

I'm not strong in cryptography, but I can not even imagine how public key may be useful by its own

I don't know either that's why generating private is the default.

Is there a way to generate a pair of private AND public keys?

You just generate the private one, all private keys contain or are able to derive its public counterpart.

const j = require('@panva/jose');

const jwk = j.JWK.generateSync('EC');

console.log(`JWK private\n`, jwk.toJWK(true));
console.log(`JWK public\n`, jwk.toJWK());

console.log(`PEM private\n`, jwk.toPEM(true));
console.log(`PEM public\n`, jwk.toPEM());
> console.log(`JWK private\n`, jwk.toJWK(true));
JWK private 
{
  crv: 'P-256',
  x: 'o5D2ZC1-ObZWkle_8phaW…

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Alexsey
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #39 on December 15, 2020 16:10.