Hasher 哈希
hasher.hash(text, algorithm, outputEncoding)
新增于:Hamibot 1.6.5
参数名 | 类型 | 说明 |
---|---|---|
text | string/buffer | 需要被哈希处理的文本或字节数据 |
algorithm | string | 可选,默认 SHA-256 ,使用的哈希算法 |
outputEncoding | string | 可选,默认 hex ,输出结果的编码格式(hex/base64) |
此函数用于对输入的文本使用指定的哈希算法进行处理,并以指定的编码格式返回摘要结果。
示例
js
var text = 'Hello Hamibot!';
log('MD5:', hasher.hash(text, 'md5')); // => 27473b72f478a38f745bc9654f4e5443
log('SHA-256:', hasher.hash(text, 'SHA-256')); // => 0a62663f5ab133d671bcae09a4d61bc4a86fc4e82749930dbe91d9280023a246
log('SHA-384:', hasher.hash(text, 'SHA-384')); // => f5a07b515760bbbfe6496fc53c1fdde6ce5afffe4ac71e15fb92502fb793b5ec286b24e03789a85e7e8c522f1c50fabe
log('SHA-512:', hasher.hash(text, 'SHA-512')); // => 413450da2b590cc5a70a2404f4b38e7cce9ebb2fa5f370e34efdf5ec5e1007e0a173107db50c22eef0c9722589e8ec1744e05c8e2466a33962f6e52627ec3c41
log('SHA-256:', hasher.sha256(text)); // => f5a07b515760bbbfe6496fc53c1fdde6ce5afffe4ac71e15fb92502fb793b5ec286b24e03789a85e7e8c522f1c50fabe
log('SHA-512:', hasher.sha512(text)); // => 413450da2b590cc5a70a2404f4b38e7cce9ebb2fa5f370e34efdf5ec5e1007e0a173107db50c22eef0c9722589e8ec1744e05c8e2466a33962f6e52627ec3c41
hasher.listAlgorithms()
新增于:Hamibot 1.6.5
该函数会列出所有可用的哈希算法。
- MD5
- SHA-1
- SHA-224
- SHA-256
- SHA-384
- SHA-512
示例
js
log('支持的算法:', hasher.listAlgorithms());
hasher.md5(text)
新增于:Hamibot 1.6.5
参数名 | 类型 | 说明 |
---|---|---|
text | string | 需要被哈希的文本 |
返回给定文本的 MD5 哈希值。
hasher.sha1(text)
新增于:Hamibot 1.6.5
参数名 | 类型 | 说明 |
---|---|---|
text | string | 需要被哈希的文本 |
返回给定文本的 SHA-1 哈希值。
hasher.sha224(text)
新增于:Hamibot 1.6.5
参数名 | 类型 | 说明 |
---|---|---|
text | string | 需要被哈希的文本 |
返回给定文本的 SHA-224 哈希值。
hasher.sha256(text)
新增于:Hamibot 1.6.5
参数名 | 类型 | 说明 |
---|---|---|
text | string | 需要被哈希的文本 |
返回给定文本的 SHA-256 哈希值。
hasher.sha384(text)
新增于:Hamibot 1.6.5
参数名 | 类型 | 说明 |
---|---|---|
text | string | 需要被哈希的文本 |
返回给定文本的 SHA-384 哈希值。
hasher.sha512(text)
新增于:Hamibot 1.6.5
参数名 | 类型 | 说明 |
---|---|---|
text | string | 需要被哈希的文本 |
返回给定文本的 SHA-512 哈希值。