Created
February 6, 2022 21:56
-
-
Save nkhil/6b3a9180d292d8b6adc1d2ddee3dc407 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const crypto = require('crypto') | |
const fs = require('fs') | |
const { publicKey, privateKey } = crypto.generateKeyPairSync("rsa", { | |
// The standard secure default length for RSA keys is 2048 bits | |
modulusLength: 2048, | |
}) | |
// ********************************************************************* | |
// | |
// To export the public key and write it to file: | |
const exportedPublicKeyBuffer = publicKey.export({ type: 'pkcs1', format: 'pem' }) | |
fs.writeFileSync('public.pem', exportedPublicKeyBuffer, { encoding: 'utf-8' }) | |
// ********************************************************************* | |
// ********************************************************************* | |
// | |
// To export the private key and write it to file | |
const exportedPrivateKeyBuffer = privateKey.export({ type: 'pkcs1', format: 'pem' }) | |
fs.writeFileSync('private.pem', exportedPrivateKeyBuffer, { encoding: 'utf-8' }) | |
// ********************************************************************* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello!,
I have a question: When do you send the file that you want the public key and the private key to be encrypted? where is the path of the file to be encrypted?
Thanks you!