aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/crypto.ts
blob: 1a583f1a09f42a48d2d9d938097d2665afd73624 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
}