-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateKeypair.js
32 lines (27 loc) · 1 KB
/
generateKeypair.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* This module will generate a public and private keypair and save to current directory
*
* Make sure to save the private key elsewhere after generated!
*/
const crypto = require("crypto");
const fs = require("fs");
function genKeyPair() {
// Generates an object where the keys are stored in properties `privateKey` and `publicKey`
const keyPair = crypto.generateKeyPairSync("rsa", {
modulusLength: 4096, // bits - standard for RSA keys
publicKeyEncoding: {
type: "pkcs1", // "Public Key Cryptography Standards 1"
format: "pem", // Most common formatting choice
},
privateKeyEncoding: {
type: "pkcs1", // "Public Key Cryptography Standards 1"
format: "pem", // Most common formatting choice
},
});
// Create the public key file
fs.writeFileSync(__dirname + "/id_rsa_pub.pem", keyPair.publicKey);
// Create the private key file
fs.writeFileSync(__dirname + "/id_rsa_priv.pem", keyPair.privateKey);
}
// Generate the keypair
genKeyPair();