No results for

Powered byAlgolia
⚠️ This is archived documentation for v0.31. Go to the latest version

createHMAC( algorithm, secret )

suggest edits

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

algorithmstringThe hashing algorithm to use. One of md4, md5, sha1, sha256, sha384, sha512, sha512_224, sha512_256 or ripemd160.
secretstring / ArrayBuffer (≥ v0.31.0)A shared secret used to sign the data.


objectA Hasher object.


1import crypto from 'k6/crypto';
3export default function () {
4 console.log(crypto.hmac('sha256', 'a secret', 'my data', 'hex'));
5 let hasher = crypto.createHMAC('sha256', 'a secret');
6 hasher.update('my ');
7 hasher.update('data');
8 console.log(hasher.digest('hex'));

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

INFO[0000] 82f669c8fde13aef6d6977257588dc4953dfac505428f8fd6b52e19cd96d7ea5
INFO[0000] 82f669c8fde13aef6d6977257588dc4953dfac505428f8fd6b52e19cd96d7ea5