How to use the md function from node-forge
Find comprehensive JavaScript node-forge.md code examples handpicked from public code repositorys.
GitHub: unparagoned/tuyapi
76 77 78 79 80 81 82 83 84 85
* Calculates a MD5 hash. * @param {String} data to hash * @returns {String} last 8 characters of hash of data */ md5(data) { const md5hash = forge.md.md5.create().update(data).digest().toHex(); return md5hash.toString().toLowerCase().substr(8, 16); } } module.exports = TuyaCipher;
76 77 78 79 80 81 82 83 84 85
}; } function generateCertsForHostname(domain, rootCAConfig) { // generate a serialNumber for domain const md = forge.md.md5.create(); md.update(domain); const keysAndCert = getKeysAndCert(md.digest().toHex()); const keys = keysAndCert.keys;
+ 59 other calls in file
GitHub: hiproxy/hiproxy
8 9 10 11 12 13 14 15 16 17
var os = require('os'); var https = require('https'); var path = require('path'); var forge = require('node-forge'); var pki = forge.pki; var md5 = forge.md.md5; var mkdirp = require('./mkdirp'); var dirtool = require('../helpers/dirTool'); var certDir = dirtool.getCertificateDir(); var defaultAttrs = [
+ 27 other calls in file
GitHub: EduWireApps/pronote-api
74 75 76 77 78 79 80 81 82 83
return cipher; } function md5(buffer) { return forge.md.md5.create().update(buffer.bytes()).digest(); } function deflate(data) {
+ 7 other calls in file
GitHub: offen/offen
123 124 125 126 127 128 129 130 131 132
serializer = serializer || JSON.stringify return asyncify(function (unencryptedValue) { var publicPEM = importPublicKey(publicJwk) var publicKey = forge.pki.publicKeyFromPem(publicPEM) var enc = publicKey.encrypt(forge.util.encodeUtf8(serializer(unencryptedValue)), 'RSA-OAEP', { md: forge.md.sha256.create() }) var result = cipher.serialize( Unibabel.binaryStringToBuffer(enc), null, ASYMMETRIC_ALGO_RSA_OAEP )
+ 11 other calls in file
GitHub: wanwu/devtools-pro
133 134 135 136 137 138 139 140 141 142
let attrs = [{name: 'commonName', value: 'DevtoolsProServer'}]; cert.setSubject(attrs); cert.setIssuer(attrs); cert.setExtensions(SERVER_EXTENSIONS); cert.sign(keys.privateKey, NodeForge.md.sha256.create()); const certPem = pki.certificateToPem(cert); const keyPem = pki.privateKeyToPem(keys.privateKey); // 创建 await mkdirp(dir);
+ 3 other calls in file
GitHub: juhoen/hybrid-crypto-js
62 63 64 65 66 67 68 69 70
switch (messageDigest) { case 'sha1': return forge.md.sha1.create(); case 'sha256': return forge.md.sha256.create(); case 'sha384': return forge.md.sha384.create();
+ 23 other calls in file
GitHub: mitro-co/keyczarjs
208 209 210 211 212 213 214 215 216 217
// check ! > 0 so that it fails for undefined if (!(iterationCount > 0)) { throw new Error('Invalid iterationCount: ' + iterationCount); } return forge.pkcs5.pbkdf2( password, salt, iterationCount, _PBE_AES_KEY_BYTES, forge.md.sha1.create()); } var PBE_DECRYPT_FAILED_MESSAGE = 'AES decryption failed (password incorrect or data is corrupt?)'; function _decryptKey(keyString, password) {
+ 3 other calls in file
GitHub: head-js/vanilla.js
2 3 4 5 6 7 8 9 10
/** * @param text [String] * @return hash [String] e.g. 21232f297a57a5a743894a0e4a801fc3 */ module.exports = function md5(text) { var md = forge.md.md5.create(); md.update(text, 'utf8'); return md.digest().toHex(); };
+ 13 other calls in file
GitHub: DNetL/magent
15 16 17 18 19 20 21 22 23 24
let i=0, ret=[]; while(i++<2) await create(864e8).then(({key,cert})=>{ cert.setSubject([{shortName:'CN', value:issuer}]); cert.setIssuer([{shortName:'CN', value:issuer}]); cert.setExtensions([{name:'basicConstraints', critical:true, cA:true}]); cert.sign(key, forge.md.sha256.create()); ret.push({key:pki.privateKeyToPem(key), cert:pki.certificateToPem(cert)}); }); return ret; }
+ 7 other calls in file
12 13 14 15 16 17 18 19 20 21
// Notes: // 1. If using an alternative hash (eg: "-md sha1") pass // "forge.md.sha1.create()" as the final parameter. // 2. If using "-nosalt", set salt to null. var salt = forge.random.getBytesSync(8); // var md = forge.md.sha1.create(); // "-md sha1" var derivedBytes = forge.pbe.opensslDeriveBytes( password, salt, keySize + ivSize/*, md*/); var buffer = forge.util.createBuffer(derivedBytes); var key = buffer.getBytes(keySize);
57 58 59 60 61 62 63 64 65 66
cert.setSubject(attrs) cert.setIssuer(attrs) cert.publicKey = forge.pki.publicKeyFromPem(keypair.public) cert.sign(forge.pki.privateKeyFromPem(keypair.private), forge.md.sha256.create()) let certPem = forge.pki.certificateToPem(cert) try { fs.unlinkSync(keyFile)
GitHub: luminati-io/luminati-proxy
108 109 110 111 112 113 114 115 116 117
cert.validity.notBefore = new Date(Date.now()-1*date.ms.DAY); cert.validity.notAfter = new Date(Date.now()+1*365*date.ms.DAY); cert.setSubject([{name: 'commonName', value: name}]); cert.setIssuer(pki.certificateFromPem(E.ca.cert).issuer.attributes); cert.setExtensions([{name: 'subjectAltName', altNames: alt_names}]); cert.sign(pki.privateKeyFromPem(E.ca.key), forge.md.sha256.create()); return cert; } function ssl(keys, extra_ssl_ips){
+ 5 other calls in file
94 95 96 97 98 99 100 101 102 103
if (supportRSA()) { getRSAKey(false, ({ pemPvt }: Object) => { const privateKey = forge.pki.privateKeyFromPem(pemPvt); const decoded64 = forge.util.decode64(encrypted); const token = privateKey.decrypt(decoded64, 'RSA-OAEP', { md: forge.md.sha256.create(), }); onSuccess(token); }); }
+ 3 other calls in file
GitHub: tokenio/sdk-js
44 45 46 47 48 49 50 51 52
* @param {Object} keys - keys to sign with * @return {string} signature */ static sign(message, keys) { // sign payload with the provided private key const md = forge.md.sha256.create(); md.update(message, 'utf8'); return base64ToBase64Url(forge.util.encode64(keys.privateKey.sign(md))); }
+ 3 other calls in file
GitHub: gitpay/util
202 203 204 205 206 207 208 209 210
name: 'subjectKeyIdentifier' }]); // self-sign certificate cert.sign(keys.private /*, forge.md.sha256.create()*/); debug('Certificate created'); return cert; }
GitHub: Andy0570/evernote
392 393 394 395 396 397 398 399 400 401
// 加密和解密,使用 RSAES-OAEP/SHA-256/MGF1-SHA-1 // 兼容 Java 的 RSA/ECB/OAEPWithSHA-256AndMGF1Padding var encrypted = publicKey.encrypt(bytes, 'RSA-OAEP', { md: forge.md.sha256.create(), mgf1: { md: forge.md.sha1.create(), }, }); var decrypted = privateKey.decrypt(encrypted, 'RSA-OAEP', { md: forge.md.sha256.create(),
+ 17 other calls in file
GitHub: ubiqsecurity/ubiq-node
28 29 30 31 32 33 34 35 36 37
// Make the (request-target) value const reqt = `${http_method} ${endpoint}`; const date = new Date(); const created = parseInt(date.getTime() / 1000, 10); // Make the body digest const md = forge.md.sha512.create(); const parsed = query ? JSON.stringify(query) : ''; md.update(parsed); // Finalise the digest const sha = forge.util.encode64(md.digest().data);
GitHub: SpiceOrz/spice
30 31 32 33 34 35 36 37 38 39
name: 'commonName', value: hostname }]); cert.setIssuer(ROOT_CRT.subject.attributes); cert.sign(ROOT_KEY, forge.md.sha256.create()); cert = { key: pki.privateKeyToPem(ROOT_KEY), cert: pki.certificateToPem(cert) };
GitHub: TA2k/ioBroker.lg-thinq
1170 1171 1172 1173 1174 1175 1176 1177 1178 1179
{ shortName: "O", value: "Amazon", }, ]); csr.sign(forge.pki.privateKeyFromPem(keys.privateKey), forge.md.sha256.create()); this.mqttdata.key = forge.pki.certificationRequestToPem(csr); } this.log.info("Create certification done"); }
+ 3 other calls in file
node-forge.pki is the most popular function in node-forge (10287 examples)