Skip to content

Latest commit

 

History

History
42 lines (31 loc) · 1.74 KB

01-createHash- algorithm -.md

File metadata and controls

42 lines (31 loc) · 1.74 KB
title description excerpt
createHash( algorithm )
Create a Hasher object, allowing the user to add data to hash multiple times, and extract hash digests along the way.
Create a Hasher object, allowing the user to add data to hash multiple times, and extract hash digests along the way.

Creates a hashing object that can then be fed with data repeatedly, and from which you can extract a hash digest whenever you want.

Parameter Type Description
algorithm string The name of the hashing algorithm you want to use. Can be any one of "md4", "md5", "sha1", "sha256", "sha384", "sha512", "sha512_224", "sha512_256", "ripemd160".

Returns

Type Description
object A Hasher object.

Example

import crypto from 'k6/crypto';

export default function () {
  console.log(crypto.sha256('hello world!', 'hex'));
  const hasher = crypto.createHash('sha256');
  hasher.update('hello ');
  hasher.update('world!');
  console.log(hasher.digest('hex'));
}

The above script should result in the following being printed during execution:

INFO[0000] 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9
INFO[0000] 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9