Answer the question
In order to leave comments, you need to log in
Writing to the file only occurs after the node js process is closed. How to fix?
const NodeRSA = require('node-rsa');
const fs = require('fs');
function makeRSAKeys(b = 1024) {
const rsa_keys = new NodeRSA({b: b});
try {
fs.statSync('./rsa_keys/public.key');
fs.statSync('./rsa_keys/private.key');
rsa_keys.importKey(fs.readFileSync('./rsa_keys/public.key', 'utf8'));
rsa_keys.importKey(fs.readFileSync('./rsa_keys/private.key', 'utf8'));
} catch (e) {
if (e.code === 'ENOENT') {
fs.writeFileSync('./rsa_keys/public.key', rsa_keys.exportKey('pkcs8-public-pem'));
fs.writeFileSync('./rsa_keys/private.key', rsa_keys.exportKey('pkcs8-private-pem'));
} else {
console.log(e);
}
}
}
makeRSAKeys();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question