aboutsummaryrefslogtreecommitdiffhomepage
path: root/packages/node-utils/src/crypto.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/node-utils/src/crypto.ts')
-rw-r--r--packages/node-utils/src/crypto.ts20
1 files changed, 20 insertions, 0 deletions
diff --git a/packages/node-utils/src/crypto.ts b/packages/node-utils/src/crypto.ts
new file mode 100644
index 000000000..1a583f1a0
--- /dev/null
+++ b/packages/node-utils/src/crypto.ts
@@ -0,0 +1,20 @@
1import { BinaryToTextEncoding, createHash } from 'crypto'
2
3function sha256 (str: string | Buffer, encoding: BinaryToTextEncoding = 'hex') {
4 return createHash('sha256').update(str).digest(encoding)
5}
6
7function sha1 (str: string | Buffer, encoding: BinaryToTextEncoding = 'hex') {
8 return createHash('sha1').update(str).digest(encoding)
9}
10
11// high excluded
12function randomInt (low: number, high: number) {
13 return Math.floor(Math.random() * (high - low) + low)
14}
15
16export {
17 randomInt,
18 sha256,
19 sha1
20}