1
0
Fork 0
peertube/shared/extra-utils/crypto.ts
2021-12-17 13:58:07 +01:00

20 lines
507 B
TypeScript

import { BinaryToTextEncoding, createHash } from 'crypto'
function sha256 (str: string | Buffer, encoding: BinaryToTextEncoding = 'hex') {
return createHash('sha256').update(str).digest(encoding)
}
function sha1 (str: string | Buffer, encoding: BinaryToTextEncoding = 'hex') {
return createHash('sha1').update(str).digest(encoding)
}
// high excluded
function randomInt (low: number, high: number) {
return Math.floor(Math.random() * (high - low) + low)
}
export {
randomInt,
sha256,
sha1
}