u
This commit is contained in:
parent
2224e9c00f
commit
386ae27a1e
8
index.js
8
index.js
@ -133,6 +133,14 @@ module.exports = {
|
|||||||
return num
|
return num
|
||||||
},
|
},
|
||||||
|
|
||||||
|
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
|
||||||
|
const 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.
|
||||||
|
const 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