-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
53 lines (42 loc) · 1.09 KB
/
main.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
46
47
48
49
50
51
52
53
'use strict';
/*
* HASH NINJA
* Quick methods for creating hashes using the native Node crypto module.
*/
const crypto = require(`crypto`);
/*
* Returns a hash of the payload using the given algorithm and encoding.
*/
function hashNinja (payload, algorithm = `sha512`, encoding = `hex`) {
const algo = crypto.createHash(algorithm);
algo.update(payload);
return algo.digest(encoding);
}
/*
* Returns an SHA512 hash of the payload.
*/
hashNinja.sha512 = function sha512 (payload, encoding = void (0)) {
return hashNinja(payload, `sha512`, encoding);
};
/*
* Returns an SHA256 hash of the payload.
*/
hashNinja.sha256 = function sha256 (payload, encoding = void (0)) {
return hashNinja(payload, `sha256`, encoding);
};
/*
* Returns an SHA1 hash of the payload.
*/
hashNinja.sha1 = function sha1 (payload, encoding = void (0)) {
return hashNinja(payload, `sha1`, encoding);
};
/*
* Returns an MD5 hash of the payload.
*/
hashNinja.md5 = function md5 (payload, encoding = void (0)) {
return hashNinja(payload, `md5`, encoding);
};
/*
* Exported methods.
*/
module.exports = hashNinja;