菜单
文档breadcrumb arrow Grafana k6breadcrumb arrow JavaScript APIbreadcrumb arrow k6/cryptobreadcrumb arrow sha512_224( input, outputEncoding )
开源

sha512_224( input, outputEncoding )

注意

存在一个 API 更好、更标准的模块。

crypto 模块部分实现了 WebCrypto API,与 k6/crypto 相比,它支持更多功能。

使用 sha512_224 来哈希输入数据。

参数类型描述
inputstring / ArrayBuffer要哈希的输入字符串或 ArrayBuffer 对象。
outputEncodingstring描述用于哈希值的编码类型。可以是 “base64”、“base64url”、“base64rawurl”、“hex” 或 “binary”。

返回值

类型描述
string / Array哈希摘要,作为字符串(适用于 “base64”、“base64url”、“base64rawurl”、“hex” outputEncoding)或原始整数数组(适用于 “binary” outputEncoding)。

示例

JavaScript
import crypto from 'k6/crypto';

export default function () {
  let hash = crypto.sha512_224('hello world!', 'hex');
  console.log(hash);
  const binArray = [104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 33];
  hash = crypto.sha512_224(new Uint8Array(binArray).buffer, 'hex');
  console.log(hash);
}

上述脚本在执行期间应打印以下内容

bash
INFO[0000] bc4ed196f7ba1c20f6fb6be1f91edf8293a35b065d6e7d6fd368c890
INFO[0000] bc4ed196f7ba1c20f6fb6be1f91edf8293a35b065d6e7d6fd368c890