Skip to content

Instantly share code, notes, and snippets.

@corocoto
Created February 4, 2023 18:53
Show Gist options
  • Save corocoto/2809363ea1b9ad521483e3e4fc4b5c96 to your computer and use it in GitHub Desktop.
Save corocoto/2809363ea1b9ad521483e3e4fc4b5c96 to your computer and use it in GitHub Desktop.
RSA key pair generator
const fs = require('fs');
const crypto = require('crypto');
function generateKeyPair() {
const keyPair = crypto.generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'pkcs1',
format: 'pem'
},
privateKeyEncoding: {
type: 'pkcs1',
format: 'pem'
}
});
fs.writeFileSync(__dirname + '/id_rsa_pub.pem', keyPair.publicKey);
fs.writeFileSync(__dirname + '/id_rsa_priv.pem', keyPair.privateKey);
}
generateKeyPair();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment