Documentation for automated readers
A curated documentation index is available at: https://grafana.com/llms.txt
A complete documentation index is available at: https://grafana.com/llms-full.txt
These indexes can help with page discovery before fetching individual documents.
This page is also available in Markdown, which may be easier for automated readers and AI tools to parse than HTML. The Markdown version is available at https://grafana.com/docs/k6/next/javascript-api/crypto/subtlecrypto/digest.md, or by sending Accept: text/markdown to https://grafana.com/docs/k6/next/javascript-api/crypto/subtlecrypto/digest/. For broader documentation discovery, the curated index is available at https://grafana.com/llms.txt and the complete index is available at https://grafana.com/llms-full.txt.
This is documentation for the next version of Grafana k6 documentation. For the latest stable release, go to the latest version.
digest
The digest() method generates a cryptographically secure digest of the given data. A digest is a short fixed-length value derived from some input data. The digest() method is commonly used to compute a checksum of data or to verify the integrity of data.
Usage
digest(algorithm, data)Parameters
| Name | Type | Description |
|---|---|---|
algorithm | a string or object with a single name string property | Names the hash function to use. Supported values are "SHA-1", "SHA-256", "SHA-384" and "SHA-512". Note that the SHA-1 hash function is not considered safe for cryptographic use. |
data | ArrayBuffer, TypedArray, or DataView | The data to be digested. |
Supported algorithms
| SHA-1 | SHA-256 | SHA-384 | SHA-512 |
|---|---|---|---|
| ✅ | ✅ | ✅ | ✅ |
Return Value
A Promise that resolves to a new ArrayBuffer containing the digest.
Example
export default async function () {
const digest = await crypto.subtle.digest('SHA-256', stringToArrayBuffer('Hello, world!'));
console.log(arrayBufferToHex(digest));
}
function arrayBufferToHex(buffer) {
return [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('');
}
function stringToArrayBuffer(s) {
return Uint8Array.from(new String(s), (x) => x.charCodeAt(0));
}Was this page helpful?
Related resources from Grafana Labs

