UNPKG

rsa-keypairgen

Version:

A Node.js library to generate RSA key pairs

20 lines (16 loc) 470 B
const crypto = require("crypto"); function generateKeyPair() { const { privateKey, publicKey } = crypto.generateKeyPairSync("rsa", { modulusLength: 4096, // The length of the key in bits publicKeyEncoding: { type: "pkcs1", format: "pem", // PEM or DER }, privateKeyEncoding: { type: "pkcs1", format: "pem", // PEM or DER }, }); return { publicKey, privateKey }; } module.exports = generateKeyPair;