How to use the node-forge.pki.privateKeyToPem function in node-forge

To help you get started, we’ve selected a few node-forge 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 sandstorm-io / sandstorm / shell / server / sandcats.js View on Github external
const csr = pki.createCertificationRequest();
  csr.publicKey = keys.publicKey;
  csr.setSubject([
    {
      name: "commonName",
      value: commonName,
      valueTagClass: asn1.Type.UTF8,
      // We specify UTF8 to encode a UTF8String (rather than the default of PRINTABLESTRING) in the
      // commonName so that GlobalSign does not report a warning, and also because that happens to
      // be what openssl(1) does when asked to create a CSR.
    },
  ]);
  csr.sign(keys.privateKey);
  console.log("generateKeyAndCsr created new key & certificate request for", commonName);
  return {
    privateKeyAsPem: pki.privateKeyToPem(keys.privateKey),
    csrAsPem: pki.certificationRequestToPem(csr),
  };
};
github mgcrea / node-easyrsa / test / spec / ssl.spec.js View on Github external
it('should properly return a privateKey and a cert', () => {
      const {privateKey, cert} = res.ca;
      const privateKeyPem = pki.privateKeyToPem(privateKey);
      expect(typeof privateKeyPem).toBe('string');
      expect(privateKeyPem).toMatch(/^-----BEGIN RSA PRIVATE KEY-----\r\n.+/);
      const certPem = pki.certificateToPem(cert);
      expect(typeof certPem).toBe('string');
      expect(certPem).toMatch(/^-----BEGIN CERTIFICATE-----\r\n.+/);
      expect(cert.serialNumber).toMatch(/[0-9a-f]{16}/);
      expect(getCertificateSubject(cert)).toEqual({commonName, ...attributes});
    });
    it('should have correct extensions', () => {
github jarrodldavis / probot-gpg / test / utils / create-private-key.js View on Github external
pki.rsa.generateKeyPair({ bits: 1024 }, (err, keyPair) => {
    if (err !== null && err !== undefined) {
      reject(err)
    } else {
      resolve(pki.privateKeyToPem(keyPair.privateKey))
    }
  })
})
github mgcrea / node-easyrsa / src / index.js View on Github external
}).tap(({privateKey, csr}) => Promise.all([
        fs.writeFileAsync(path.join(this.dir, 'reqs', `${commonName}.req`), pki.certificationRequestToPem(csr)),
        fs.writeFileAsync(path.join(this.dir, 'private', `${commonName}.key`), pki.privateKeyToPem(privateKey))
      ]));
  }
github michaellperry / jinaga / src / memory / memory-keystore.ts View on Github external
private generateKeyPair(key: string) {
        const keypair = pki.rsa.generateKeyPair({ bits: 1024 });
        const privateKey = pki.privateKeyToPem(keypair.privateKey);
        const publicKey = pki.publicKeyToPem(keypair.publicKey);
        this.keyPairs[key] = { publicKey, privateKey };
        return publicKey;
    }
}
github tngan / samlify / src / utility.ts View on Github external
export function readPrivateKey(keyString: string | Buffer, passphrase: string | undefined, isOutputString?: boolean) {
  return isString(passphrase) ? this.convertToString(pki.privateKeyToPem(pki.decryptRsaPrivateKey(String(keyString), passphrase)), isOutputString) : keyString;
}
/**
github poetapp / poet-js / src / util / KeyHelper.ts View on Github external
export const generateRsaKeyPems = () => {
  const keyPair = generateRsaKeyPair()
  return {
    publicKey: pki.publicKeyToPem(keyPair.publicKey),
    privateKey: pki.privateKeyToPem(keyPair.privateKey),
  }
}