function hash (filename, cb) { const sha = crypto.createHash('sha512') sha.update('clinic\n') fs.createReadStream(filename) .on('data', data => sha.update(data)) .on('end', () => cb(null, sha.digest())) .on('error', cb) }
transporterReceive(next) { return (cmd, data, s) => { const decrypter = iv ? crypto.createDecipheriv(algorithm, password, iv) : crypto.createDecipher(algorithm, password); const res = Buffer.concat([decrypter.update(data), decrypter.final()]); return next(cmd, res, s); }; }
const hmacSHA1 = (key: string, data: string) => { // hmac.digest([encoding]) // If encoding is provided a string is returned; otherwise a Buffer is returned; return crypto.createHmac('sha1', key).update(data).digest().toString('base64'); }
// Returns a new random hex string of the given even size. function randomHexString(size) { if (size === 0) { throw new Error('Zero-length randomHexString is useless.'); } if (size % 2 !== 0) { throw new Error('randomHexString size must be divisible by 2.'); } return (0, _crypto.randomBytes)(size / 2).toString('hex'); }
constructor(mongoDatabaseURI = _defaults.default.DefaultMongoURI, mongoOptions = {}, fileKey = undefined) { super(); this._databaseURI = mongoDatabaseURI; this._algorithm = 'aes-256-gcm'; this._fileKey = fileKey !== undefined ? crypto.createHash('sha256').update(String(fileKey)).digest('base64').substr(0, 32) : null; const defaultMongoOptions = { useNewUrlParser: true, useUnifiedTopology: true }; this._mongoOptions = Object.assign(defaultMongoOptions, mongoOptions); }
fileHash(file) { return new Promise((resolve, reject) => { const hash = crypto.createHash('sha1'); const stream = fs.createReadStream(file); stream.on('error', err => reject(err)); stream.on('data', chunk => hash.update(chunk)); stream.on('end', () => resolve(hash.digest('hex'))); }); }
const sha1 = path => new Promise((resolve, reject) => { const hash = crypto.createHash("sha1"); const rs = fs.createReadStream(path); rs.on("error", reject); rs.on("data", chunk => hash.update(chunk)); rs.on("end", () => resolve(hash.digest("hex"))); })
function getAppSecretPath(authData, options = {}) { const appSecret = options.appSecret; if (!appSecret) { return ''; } const appsecret_proof = crypto .createHmac('sha256', appSecret) .update(authData.access_token) .digest('hex'); return `&appsecret_proof=${appsecret_proof}`; }
function sha1(data) { return crypto .createHash("sha1") .update(data, "binary") .digest("hex"); }
function sha1(data) { return crypto .createHash("sha1") .update(data, "binary") .digest("hex"); }
function sha1(data) { return crypto .createHash("sha1") .update(data, "binary") .digest("hex"); }
function sha1(data) { return crypto .createHash("sha1") .update(data, "binary") .digest("hex"); }
function getAppSecretPath(authData, options = {}) { const appSecret = options.appSecret; if (!appSecret) { return ''; } const appsecret_proof = crypto.createHmac('sha256', appSecret).update(authData.access_token).digest('hex'); return `&appsecret_proof=${appsecret_proof}`; }