1
0
Fork 0
mirror of https://github.com/codex-team/codex.docs.git synced 2025-07-21 06:09:41 +02:00
codex.docs/src/utils/crypto.js

34 lines
605 B
JavaScript
Raw Normal View History

const crypto = require('crypto');
/**
* Create binary md5
* @param stringToHash - string to hash
* @returns {string} - binary hash of argument
*/
function binaryMD5(stringToHash) {
return crypto.createHash('md5')
.update(stringToHash)
.digest('binary');
}
/**
* 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
};