2019-01-25 02:23:00 +03:00
|
|
|
const crypto = require('crypto');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create binary md5
|
|
|
|
* @param stringToHash - string to hash
|
|
|
|
* @returns {string} - binary hash of argument
|
|
|
|
*/
|
2019-03-11 18:44:00 +03:00
|
|
|
function binaryMD5(stringToHash) {
|
2019-01-25 02:23:00 +03:00
|
|
|
return crypto.createHash('md5')
|
|
|
|
.update(stringToHash)
|
|
|
|
.digest('binary');
|
2019-03-11 18:44:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns 16 random bytes in hex format
|
|
|
|
* @return {Promise<string>}
|
|
|
|
*/
|
|
|
|
function random16() {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
crypto.randomBytes(16, (err, raw) => {
|
|
|
|
if (err) {
|
|
|
|
reject(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
resolve(raw.toString('hex'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
binaryMD5,
|
|
|
|
random16
|
2019-01-25 02:23:00 +03:00
|
|
|
};
|