-
Notifications
You must be signed in to change notification settings - Fork 3
/
hash.js
45 lines (39 loc) · 1.03 KB
/
hash.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const crypto = require('crypto')
module.exports = {
/**
* Compute a SHA-256 hash of a given string.
*
* @param {string} text - The text to calculate into a hash.
* @returns {Promise<Buffer>}
*/
sha256: (text) => {
return new Promise((resolve, reject) => {
let hash = crypto.createHash('sha256')
return resolve(hash.update(text).digest())
})
},
/**
* Compute a SHA-384 hash of a given string.
*
* @param {string} text - The text to calculate into a hash.
* @returns {Promise<Buffer>}
*/
sha384: (text) => {
return new Promise((resolve, reject) => {
let hash = crypto.createHash('sha384')
return resolve(hash.update(text).digest())
})
},
/**
* Compute a SHA-512 hash of a given string.
*
* @param {string} text - The text to calculate into a hash.
* @returns {Promise<Buffer>}
*/
sha512: (text) => {
return new Promise((resolve, reject) => {
let hash = crypto.createHash('sha512')
return resolve(hash.update(text).digest())
})
}
}