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