File tree Expand file tree Collapse file tree 1 file changed +19
-16
lines changed
Expand file tree Collapse file tree 1 file changed +19
-16
lines changed Original file line number Diff line number Diff line change 33const crypto = require ( 'crypto' ) ;
44
55/**
6- * Export `StringUtil`.
6+ * @module CryptoUtil
77 */
88
9- module . exports = {
10- /**
11- *
12- * @param algorithm {String} the hash algorithm, default is 'sha256'
13- * @param data {Buffer|String|TypedArray|DataView} the data to hash
14- * @param encoding {String|undefined} optional, the encoding to calculate the
15- * digest
16- * @return {Buffer|String } if {encoding} undefined a {Buffer} is returned, otherwise a {String}
17- */
18- createHash : function ( { algorithm = 'sha256' , data = undefined , encoding = undefined } ) {
19- return crypto
20- . createHash ( algorithm )
21- . update ( data )
22- . digest ( encoding ) ;
23- }
9+ /**
10+ * Creates a new hash by given algorithm, data and digest encoding.
11+ * Defaults to sha256 as.
12+ *
13+ * @function
14+ * @param algorithm {string} the hash algorithm, default is 'sha256'
15+ * @param data {Buffer|string|TypedArray|DataView} the data to hash
16+ * @param encoding {string=} optional, the encoding of the input
17+ * @param output {'base64'|'base64url'|'binary'|'hex'|undefined} optional, the desired output type
18+ * @return {Buffer|string } if {output} is undefined, a {Buffer} is returned, otherwise a {String}
19+ */
20+ const createHash = function ( { algorithm = 'sha256' , data, output, encoding } ) {
21+ return crypto
22+ . createHash ( algorithm )
23+ . update ( data , encoding )
24+ . digest ( output ) ;
2425} ;
26+
27+ module . exports = { createHash } ;
You can’t perform that action at this time.
0 commit comments