UNPKG

vpn.email

Version:
42 lines (41 loc) 1.56 kB
"use strict"; /// <reference path="../../../typings/tsd.d.ts" /> /** * NewKeyPair * @param email <string> email address * @param name <string> name * @param keyBitLength <string> key bit length * @param password <string> password */ const openpgp = require("openpgp"); const fs = require("fs"); const path = require("path"); const osenv = require("osenv"); const setupFolderName = '/Vpn.Email'; const localPath = path.parse(osenv.home() + setupFolderName); const cer_PrivfileName = path.parse(path.format(localPath) + '/systemCerPriv.key.pem'); const cer_PubfileName = path.parse(path.format(localPath) + '/systemCerPub.key.pem'); const env = process.env; console.log(env); const NewKeyPair = (email, name, keyBitLength, password) => { const userId = { name: name, email: email }; const option = { numBits: parseInt(keyBitLength ? keyBitLength : '1024'), passphrase: password, userIds: userId }; openpgp.generateKey(option).then((keypair) => { // success fs.writeFileSync(path.format(cer_PrivfileName), keypair.privateKeyArmored, { encoding: 'utf8' }); fs.writeFileSync(path.format(cer_PubfileName), keypair.publicKeyArmored, { encoding: 'utf8' }); process.exit(0); }).catch((err) => { // ERROR console.log(err); process.exit(1); }); }; NewKeyPair(env.email, env.userName, env.keyBitLength.toString(), env.keyPassword);