Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature-request: retrieve public-key from private-key(pem) #7

Closed
alpastar opened this issue Dec 31, 2019 · 1 comment
Closed

feature-request: retrieve public-key from private-key(pem) #7

alpastar opened this issue Dec 31, 2019 · 1 comment
Assignees

Comments

@alpastar
Copy link

get, or create RSA key-pair and convert cryptoKey(private) to pem

from this pem(private), can i retrieve public key ?
if not , what about add such method ...

@alpastar alpastar changed the title feature-request retrieve public-key from private-key(pem) feature-request: retrieve public-key from private-key(pem) Dec 31, 2019
@PeterBielak PeterBielak self-assigned this May 26, 2020
@PeterBielak
Copy link
Member

Hi there, thank you for the suggestion. It is very appreciated!

I just published a new version v1.5.3, which includes support for public key retrieval using the getPublicKey method.

Please see the code below as a reference on how you can retrieve a public key from an RSA-OAEP, RSA-PSS, ECDH, or ECDSA private key.

const keyPair = await crypt.getRSAKeyPair()
console.log(keyPair)

const pemPrivateKey = await crypt.cryptoPrivateToPem(keyPair.privateKey)
console.log(pemPrivateKey)

const cryptoPrivateKey = await crypt.pemPrivateToCrypto(pemPrivateKey)
console.log(cryptoPrivateKey)

const publicKey = await crypt.getPublicKey(cryptoPrivateKey)
console.log(publicKey)

Feel free to let me know if you need any further help.

Best Regards,
Peter Bielak

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants