How to use keypair - 5 common examples

To help you get started, we’ve selected a few keypair 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 jwarkentin / node-monkey / server / app.js View on Github external
throw new Error(`Options 'dataDir' is required to enable SSH`)
      }

      // Get host keys
      let files = fs.readdirSync(dataDir),
          keyRe = /\.key$/,
          hostKeys = []
      for (let file of files) {
        if (keyRe.test(file)) {
          hostKeys.push(`${dataDir}/${file}`)
        }
      }

      if (!hostKeys.length) {
        console.log('No SSH host key found. Generating new host key...')
        let keys = keypair()
        fs.writeFileSync(`${dataDir}/rsa.key`, keys.private)
        fs.writeFileSync(`${dataDir}/rsa.key.pub`, keys.public)
        hostKeys = [ `${dataDir}/rsa.key` ]
      }

      this.SSHMan = new SSHMan({
        monkey: this,
        cmdManager: this._cmdMan,
        userManager: this.userManager,
        silent: this.options.server.silent,
        host: sshOpts.host,
        port: sshOpts.port,
        title: _.result(sshOpts, 'title'),
        prompt: _.result(sshOpts, 'prompt'),
        hostKeys
      })
github reactioncommerce / reaction-cli / src / utils / ssh.js View on Github external
export function generateKeyPair({ email }) {
  if (!email) {
    Log.error('An email is required to generate a keypair');
    process.exit(1);
  }

  const pair = keypair();
  const pub = pki.publicKeyFromPem(pair.public);
  const priv = pki.privateKeyFromPem(pair.private);

  const publicKey = ssh.publicKeyToOpenSSH(pub, email);
  const privateKey = ssh.privateKeyToOpenSSH(priv);

  const userHome = os.homedir();
  const title = uuid.v1();

  const publicKeyFile = path.resolve(`${userHome}/.reaction/keys/${title}.pub`);
  const privateKeyFile = path.resolve(`${userHome}/.reaction/keys/${title}`);

  fs.ensureFileSync(publicKeyFile);
  fs.ensureFileSync(privateKeyFile);

  fs.writeFileSync(publicKeyFile, publicKey);
github michaellperry / jinaga / mongo / mongo-keystore.ts View on Github external
private async generateKeyPair(connection: Connection, userIdentity: UserIdentity) {
        const pair = Keypair({ bits: 1024 });
        const privateKey = pair.private;
        const publicKey = pair.public;
        await connection.insertOne({
            provider: userIdentity.provider,
            userId: userIdentity.id,
            privateKey: privateKey,
            publicKey: publicKey
        });
        return publicKey;
    }
}
github jolocom / smartwallet-app / src / js / lib / blockchain / wallet-crypto.js View on Github external
generatePrivateRSAKey() {
    let pair = new Keypair({bits: 1024})
    let privateKey = pair.private.substring(32)
    privateKey = privateKey.substring(0, privateKey.length - 31)
    return privateKey
  }
  computeCompressedEthereumPublicKey(privKey) {
github transistorsoft / background-geolocation-console / src / server / libs / jwt.js View on Github external
export const makeKeys = async () => {
  if (existsSync(privateKeyFile)) {
    return;
  }

  const keys = rsaGen();
  const options = { flag: 'w', encoding: 'utf8' };

  writeFileSync(privateKeyFile, keys.private, options);
  writeFileSync(publicKeyFile, keys.public, options);
};

keypair

Generate a RSA PEM key pair from pure JS

BSD / GPL
Latest version published 3 years ago

Package Health Score

50 / 100
Full package analysis

Popular keypair functions