1
0
Fork 0
mirror of https://github.com/codex-team/codex.docs.git synced 2025-07-19 05:09:41 +02:00
codex.docs/src/backend/utils/crypto.ts
2022-04-24 14:11:51 +03:00

36 lines
669 B
TypeScript

import crypto from 'crypto';
/**
* Create binary md5
*
* @param stringToHash - string to hash
* @returns {string} - binary hash of argument
*/
export function binaryMD5(stringToHash: string): string {
return crypto.createHash('md5')
.update(stringToHash)
.digest()
.toString('binary');
}
/**
* Returns 16 random bytes in hex format
*
* @returns {Promise<string>}
*/
export function random16(): Promise<string> {
return new Promise((resolve, reject) => {
crypto.randomBytes(16, (err, raw) => {
if (err) {
reject(err);
}
resolve(raw.toString('hex'));
});
});
}
export default {
binaryMD5,
random16,
};