How to use the node-forge.md 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 letsencrypt / boulder / test / js / crypto-util.js View on Github external
// Create and sign the CSR
    var csr = forge.pki.createCertificationRequest();
    csr.publicKey = publicKey;
    csr.setSubject([{ name: 'commonName', value: names[0] }]);

    var sans = [];
    for (i in names) {
      sans.push({ type: 2, value: names[i] });
    }
    csr.setAttributes([{
      name: 'extensionRequest',
      extensions: [{name: 'subjectAltName', altNames: sans}]
    }]);

    csr.sign(privateKey, forge.md.sha256.create());

    // Convert CSR -> DER -> Base64
    var der = forge.asn1.toDer(forge.pki.certificationRequestToAsn1(csr));
    return util.b64enc(bytesToBuffer(der));
  },
github jfromaniello / selfsigned / index.js View on Github external
keyCertSign: true,
      digitalSignature: true,
      nonRepudiation: true,
      keyEncipherment: true,
      dataEncipherment: true
    }, {
      name: 'subjectAltName',
      altNames: [{
        type: 6, // URI
        value: 'http://example.org/webid#me'
      }]
    }]);

    cert.sign(keyPair.privateKey, getAlgorithm(options && options.algorithm));

    const fingerprint = forge.md.sha1
                          .create()
                          .update(forge.asn1.toDer(forge.pki.certificateToAsn1(cert)).getBytes())
                          .digest()
                          .toHex()
                          .match(/.{2}/g)
                          .join(':');

    var pem = {
      private:     forge.pki.privateKeyToPem(keyPair.privateKey),
      public:      forge.pki.publicKeyToPem(keyPair.publicKey),
      cert:        forge.pki.certificateToPem(cert),
      fingerprint: fingerprint,
    };

    if (options && options.pkcs7) {
      var p7 = forge.pkcs7.createSignedData();
github wuchangming / https-mitm-proxy-handbook / code / chapter3 / createCertByRootCA.js View on Github external
cRLSign: true,
    encipherOnly: true,
    decipherOnly: true
}, {
    name: 'subjectKeyIdentifier'
}, {
    name: 'extKeyUsage',
    serverAuth: true,
    clientAuth: true,
    codeSigning: true,
    emailProtection: true,
    timeStamping: true
}, {
    name: 'authorityKeyIdentifier'
}]);
cert.sign(caKey, forge.md.sha256.create());

var certPem = pki.certificateToPem(cert);
var keyPem = pki.privateKeyToPem(keys.privateKey);
console.log(certPem);
console.log(keyPem);


mkdirp.sync(path.join(__dirname, '../../cert'));
fs.writeFileSync(path.join(__dirname, '../../cert/my.crt'), certPem);
fs.writeFileSync(path.join(__dirname, '../../cert/my.key.pem'), keyPem);
github jfromaniello / selfsigned / index.js View on Github external
function getAlgorithm(key) {
  switch (key) {
    case 'sha256':
      return forge.md.sha256.create();
    default:
      return forge.md.sha1.create();
  }
}
github wuchangming / https-mitm-proxy-handbook / code / chapter4 / createFakeHttpsWebSite.js View on Github external
},
    {
        name: 'subjectKeyIdentifier'
    },
    {
        name: 'extKeyUsage',
        serverAuth: true,
        clientAuth: true,
        codeSigning: true,
        emailProtection: true,
        timeStamping: true
    },
    {
        name:'authorityKeyIdentifier'
    }]);
    cert.sign(caKey, forge.md.sha256.create());

    return {
        key: keys.privateKey,
        cert: cert
    };
}
github digitalbazaar / jsonld-signatures / lib / LDKeyPair.js View on Github external
function createPss() {
  const md = forge.md.sha256.create();
  return forge.pss.create({
    md,
    mgf: forge.mgf.mgf1.create(forge.md.sha256.create()),
    saltLength: md.digestLength
  });
}
github topcoder-platform / community-app / src / shared / containers / NewsletterSignupForMembers.jsx View on Github external
async checkSubscription() {
    const {
      listId, user, token, authenticating,
    } = this.props;
    if (!token || authenticating) return;
    const md = forge.md.md5.create();
    md.update(user.email);

    this.emailHash = md.digest().toHex();

    await fetch(`${PROXY_ENDPOINT}/${listId}/members/${this.emailHash}`, {
      method: 'GET',
      headers: {
        'Content-Type': 'application/json',
      },
    })
      .then((result) => {
        if (result.status === 400) this.setState({ signupState: SIGNUP_NEWSLETTER.DEFAULT });
        return result.json();
      })
      .then((dataResponse) => {
        if (dataResponse.status === 'subscribed') {
github kobotoolbox / enketo-express / public / js / src / module / encryptor.js View on Github external
function _md5Digest( byteString ) {
    const md = forge.md.md5.create();
    md.update( byteString );
    return md.digest();
}
github Litarvan / pronote-api / src / cipher.js View on Github external
string = forge.util.encodeUtf8('' + string);

    //let original = string;

    if (compress && !session.disableCompress)
    {
        string = new forge.util.ByteBuffer(string).toHex();
        string = pako.deflateRaw(string, {
            level: 6,
            to: 'string'
        })
    }

    let key = forge.md.md5.create().update(rsaKey.bytes()).digest();
    let iv = session.ivAES.length() ? forge.md.md5.create().update(session.ivAES.bytes()).digest() : new forge.util.ByteBuffer();

    let cipher = forge.cipher.createCipher('AES-CBC', key);
    cipher.start({
        iv: iv
    });
    cipher.update(new forge.util.ByteBuffer(string));

    return cipher.finish() && cipher.output.toHex();
    /*let result = cipher.finish() && cipher.output.toHex();
    return forge.md.md5.create().update(original).update(rsaKey.bytes()).digest().toHex().toUpperCase() + result;*/
}
github C0k3 / session / lib / secrets.js View on Github external
passwordDigest: function(password) {
        let md = forge.md.sha256.create();
        md.update(password + process.env.PASSWORD_SALT);
        return md.digest().toHex();
    } 
};