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

sha384( input, outputEncoding )

注意

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

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

使用 sha384 对输入数据进行哈希计算。

参数类型描述
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.sha384('hello world!', 'hex');
  console.log(hash);
  const binArray = [104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 33];
  hash = crypto.sha384(new Uint8Array(binArray).buffer, 'hex');
  console.log(hash);
}

上述脚本执行时应打印以下内容

bash
INFO[0000] d33d40f7010ce34aa86efd353630309ed5c3d7ffac66d988825cf699f4803ccdf3f033230612f0945332fb580d8af805
INFO[0000] d33d40f7010ce34aa86efd353630309ed5c3d7ffac66d988825cf699f4803ccdf3f033230612f0945332fb580d8af805