资料
digitalbazaar/forge
const forge = require('node-forge'); const path = require('path') const fs = require('fs-extra') const {rsa, publicKeyToPem, privateKeyToPem} = forge.pki; const rsaFilePath = path.join(__dirname, '../config/rsa.js') rsa.generateKeyPair({bits: 2048, workers: 2}, function (err, keypair) { if (err) { return; } const rsaKey = { RSAPublicKey: publicKeyToPem(keypair.publicKey).replace(/\r/g, ''), RSAPrivateKey: privateKeyToPem(keypair.privateKey).replace(/\r/g, ''), } console.log(rsaKey); fs.outputFileSync(rsaFilePath, 'module.exports = ' + JSON.stringify(rsaKey)) });