添加了 hash 方法,使得前端不必依赖 tic.crypto 而减小体积。
This commit is contained in:
parent
6610549a00
commit
11d3a2cf7a
10
index.js
10
index.js
@ -130,4 +130,14 @@ module.exports = {
|
||||
return format
|
||||
},
|
||||
|
||||
hash(data, {hasher='sha256', salt, input='utf8', output='hex'}={}){
|
||||
if (typeof(data)!=='string' && !(data instanceof Buffer) && !(data instanceof DataView))
|
||||
data=JSON.stringify(data)
|
||||
if (salt && typeof(salt)==='string')
|
||||
data=data+salt
|
||||
let inputEncoding=input // my.INPUT_LIST.indexOf(option.input)>=0?option.input:my.INPUT // 'utf8', 'ascii' or 'latin1' for string data, default to utf8 if not specified; ignored for Buffer, TypedArray, or DataView.
|
||||
let outputEncoding=(output==='buf')?undefined:output // (my.OUTPUT_LIST.indexOf(output)>=0?output:my.OUTPUT) // option.output: 留空=》默认输出hex格式;或者手动指定 'buf', hex', 'latin1' or 'base64'
|
||||
return require('crypto').createHash(hasher).update(data, inputEncoding).digest(outputEncoding)
|
||||
},
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user