1 const crypto = require("crypto");
2 const { generateKeyPair } = require("crypto");
4 const TAG = '[DeviceHome][security.js]';
6 module.exports.Security = class Security {
12 getKeyPairPromise(pincode) {
13 console.log(`${TAG} getKeyPairPromise`);
14 return new Promise((resolve, reject) => {
15 console.log(`${TAG} Generating key will take some time..`);
16 generateKeyPair("rsa", {
25 // TODO: Enable ciper and passphrase
26 //cipher: "aes-256-cbc",
29 }, (err, publicKey, privateKey) => {
30 // Handle errors and use the generated key pair.
33 privateKey: privateKey
40 return this.getKeyPairPromise(req).then(r => {
41 req.session.privateKey = r.privateKey;
42 req.session.publicKey = r.publicKey;
43 console.log(`${TAG}[awaitKeyPair] RSA keys are generated`);
45 console.log(`${TAG} Error : ${err}`);