Minel Aydın
Minel Aydın

Reputation: 137

How to create public/private key encryption- node js

Hi I'd like to generate a public/private keypair in node-js, and use the public key to encrypt message and the private key to decrypt the message.

I need to encode user's secretKey because I use them for individually validation. And then I should decode it. I guess I can use public/private key encryption for this.

I know window.crypto.subtle.generateKey and here is a lot of examples about encryption algorithms https://github.com/diafygi/webcrypto-examples/#aes-gcm . But I guess for using them I need to import window-crypto. And I'm confused about which one I should use and how.

Is there any source, an example or a suggestion for me to do this using node-js?

EDIT: I have learnt that there is no function in javascript that can decode the secret key of token. Secret key is created with special alghoritms.

Upvotes: 1

Views: 2412

Answers (1)

Vinay Prajapati
Vinay Prajapati

Reputation: 7546

There must be different approaches and plugins available. I did quick exploration and jsencrypt can be used for your case.

git hub link - https://github.com/travist/jsencrypt

Also, you can refer to https://medium.com/sharenowtech/high-speed-public-key-cryptography-in-javascript-part-1-3eefb6f91f77

Upvotes: 1

Related Questions