sha1( input, outputEncoding )
注意
存在一个具有更好、更标准 API 的模块。
该 crypto 模块 部分实现了 WebCrypto API,支持比 k6/crypto 更多的功能。
使用 sha1 对输入数据进行哈希计算。
参数 | 类型 | 描述 |
---|---|---|
input | 字符串 / ArrayBuffer | 要进行哈希计算的输入字符串或 ArrayBuffer 对象。 |
outputEncoding | 字符串 | 描述用于哈希值的编码类型。可以是“base64”、“base64url”、“base64rawurl”、“hex”或“binary”。 |
返回值
类型 | 描述 |
---|---|
字符串 / 数组 | 哈希摘要作为字符串(对于“base64”、“base64url”、“base64rawurl”、“hex” outputEncoding )或原始整数数组(对于“binary” outputEncoding )。 |
示例
import crypto from 'k6/crypto';
export default function () {
let hash = crypto.sha1('hello world!', 'hex');
console.log(hash);
const binArray = [104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 33];
hash = crypto.sha1(new Uint8Array(binArray).buffer, 'hex');
console.log(hash);
}
上述脚本在执行期间应输出以下结果
INFO[0000] 430ce34d020724ed75a196dfc2ad67c77772d169
INFO[0000] 430ce34d020724ed75a196dfc2ad67c77772d169