How to use the openpgp.generateKey function in openpgp

To help you get started, we’ve selected a few openpgp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github autocrypt / autocrypt-js / test / util.js View on Github external
setup: function (fromAddr, cb) {
    var crypt = autocrypt({storage: memdb({valueEncoding: 'json'})})
    openpgp.initWorker({ path: 'openpgp.worker.js' }) // set the relative web worker path
    openpgp.config.aead_protect = true // activate fast AES-GCM mode (not yet OpenPGP standard)

    openpgp.generateKey({
      userIds: [{ name: 'Jon Smith', email: fromAddr }],
      numBits: 1096,
      passphrase: 'super long and hard to guess'
    }
    ).then((key) => cb(crypt, decode(key.publicKeyArmored), done)
  ).catch((err) => { throw err })

    function done (cb) {
      crypt.storage.close(cb)
    }
  },
  decode: decode
github transmute-industries / transmute / packages / transmute-cli / src / commands / generate-keys / index.js View on Github external
userIds: [
      {
      }
    ],
    curve: 'secp256k1',
    passphrase: args.passphrase
  }

  // create primary key
  const primaryKeyPair = await openpgp.generateKey(secOptions)
  let primarySk = openpgp.key.readArmored(primaryKeyPair.privateKeyArmored)
    .keys[0]
  await primarySk.decrypt(args.passphrase)

  // create recovery key
  const recoveryKeyPair = await openpgp.generateKey(secOptions)
  const recoverySk = openpgp.key.readArmored(recoveryKeyPair.privateKeyArmored)
    .keys[0]
  await recoverySk.decrypt(args.passphrase)

  // sign primary key with recovery key
  primarySk = await primarySk.signPrimaryUser([recoverySk])

  // lock private keys before exporting them
  await primarySk.encrypt(args.passphrase)
  await recoverySk.encrypt(args.passphrase)

  let transmuteDir = path.join(require('os').homedir(), '.transmute/cli-secrets')

  // write private keys temporarily to secrets directory
  await writeFile(path.join(transmuteDir, 'primary_sk.key'), primarySk.armor())
  await writeFile(path.join(transmuteDir, 'recovery_sk.key'), recoverySk.armor())
github QTGate / QTGate-Desktop-Client / app / newKeyPair.ts View on Github external
const NewKeyPair = ( data: INewKeyPair, CallBack ) => {
    
    const userId = {
		name: data.nikeName,
		email: data.email
    }

    const option = {
        numBits: parseInt ( data.keyLength || '2048' ),
        passphrase: data.password,
        userIds: userId
    }

    openpgp.generateKey ( option ).then (( keypair: { publicKeyArmored: string, privateKeyArmored: string }) => {
        
        const ret: keyPair = {
            publicKey: keypair.publicKeyArmored,
            privateKey: keypair.privateKeyArmored
		}
        return CallBack( null, ret )
    }).catch ( err => {
		// ERROR
        return CallBack ( err )
    })
}
github isomorphic-git / isomorphic-git / src / models / PGP.js View on Github external
static async keygen (name, email) {
    const { privateKeyArmored, publicKeyArmored } = await openpgp.generateKey({
      userIds: [
        {
          name: name,
          email: email
        }
      ]
    })
    keyring.publicKeys.importKey(publicKeyArmored)
    keyring.privateKeys.importKey(privateKeyArmored)
    // let key = openpgp.key.readArmored(privateKeyArmored).keys[0]
    // key.toString = printKey
    // We need to manually call this to save the keypair to localstorage
    keyring.store()
  }
github QTGate / CoNET / core / tools / initSystem.js View on Github external
exports.newKeyPair = (emailAddress, nickname, password, CallBack) => {
    const userId = {
        name: nickname,
        email: emailAddress
    };
    const option = {
        passphrase: password,
        userIds: [userId],
        curve: "ed25519",
        aead_protect: true,
        aead_protect_version: 4
    };
    return OpenPgp.generateKey(option).then((keypair) => {
        const ret = {
            publicKey: keypair.publicKeyArmored,
            privateKey: keypair.privateKeyArmored
        };
        return CallBack(null, ret);
    }).catch(err => {
        // ERROR
        return CallBack(err);
    });
};
exports.getImapSmtpHost = function (_email) {
github ProtonMail / WebClient / src / app / libraries / pmcrypto.js View on Github external
function generateKeysRSA(email = '', passphrase = '', numBits = 2048) {

        if (passphrase.length === 0) {
            return Promise.reject('Missing private key passcode');
        }

        const user = {
            name: email,
            email
        };

        return openpgp.generateKey({
            numBits,
            userIds: [user],
            passphrase
        });
    }
github henryboldi / felony / app / utils / pgp.js View on Github external
export async function generateKey({ name, email = '' }, passphrase) {
  const key = await openpgp.generateKey({
    userIds: [{ name, email }],
    numBits: 4096,
    passphrase,
  })

  return {
    name,
    email,
    privateKeyArmored: applyFelonyBranding(key.privateKeyArmored),
    publicKeyArmored: applyFelonyBranding(key.publicKeyArmored),
  }
}
github NEEOInc / neeo-sdk / src / lib / expressBrainDriver / crypto / index.ts View on Github external
function generateKey() {
  configOpenPgp();
  const startTime = Date.now();
  const passphrase = crypto.randomBytes(64).toString();
  /*
   * Since we use a random passphrase on each start, the user
   * isn't important, however it is required by openpgp to generate
   * the key.
   */
  const keyGenOptions = {
    userIds: [PGP_USER],
    numBits: RSA_KEYLENGTH,
    passphrase,
  };
  debug('generating keys');
  return openpgp.generateKey(keyGenOptions).then(
    (key): void | Promise => {
      publicKeyAscii = key.publicKeyArmored;
      publicKeys = openpgp.key.readArmored(key.publicKeyArmored).keys;
      privateKey = openpgp.key.readArmored(key.privateKeyArmored).keys[0];
      if (!privateKey.decrypt(passphrase)) {
        debug('key generation failed %o', {
          durationMs: Date.now() - startTime,
        });
        return Promise.reject(new Error('Wrong passphrase! Could not decrypt the private key!'));
      }
      debug('key generation complete %o', {
        durationMs: Date.now() - startTime,
      });
    }
  );
}
github shibacomputer / txt / app / main / pgp.js View on Github external
export async function make(user, secret) {
  const opts = {
    userIds: [{ name: user }],
    curve: 'brainpoolP512r1',
    passphrase: secret
  }

  let key

  try {
    key = await openpgp.generateKey(opts)
  } catch (e) {
    throw e
  }
  return key
}
github kenforthewin / mentat / assets / js / actions / cryptoActions.js View on Github external
return (dispatch, getState) => {
    const passphrase = randomWords({ exactly: 10, join: ' ' })
    const options = {
      userIds: [{ name:'Example Example', email:'example@example.com' }],
      numBits: 2048,
      passphrase: passphrase
    };

    openpgp.generateKey(options).then((key) => {
      const privateKey = key.privateKeyArmored;
      const publicKey = key.publicKeyArmored;
      dispatch({
        type: 'new_key',
        passphrase,
        privateKey,
        publicKey
      });
    });
  }
}