Menu
Scroll for more
This is documentation for the next version of Grafana k6 documentation. For the latest stable release, go to the latest version.
Open source
createHash( algorithm )
Note
A module with a better and standard API exists.
The crypto module partially implements the WebCrypto API, supporting more features than k6/crypto.
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
JavaScript
JavaScript
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:
Bash
INFO[0000] 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9
INFO[0000] 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9Was this page helpful?
Related resources from Grafana Labs
Additional helpful documentation, links, and articles:
Video

Performance testing and observability in Grafana Cloud
Optimize user experiences with Grafana Cloud. Learn real-time insights, performance testing with k6, and continuous validation with Synthetic Monitoring.
Events

User-centered observability: load testing, real user monitoring, and synthetics
Learn how to use load testing, synthetic monitoring, and real user monitoring (RUM) to understand end users' experience of your apps. Watch on demand.