The Sha2Algorithm class is an implementation of the Hasher interface for the SHA-2 family of cryptographic hash functions. The digest method takes the algorithm identifier of the hash function and arbitrary data as input and returns the hash digest of the data.

This class is typically accessed through implementations that extend the CryptoApi interface.

Hierarchy (view full)

Implements

Constructors

Methods

Constructors

Methods

  • Generates a hash digest of the provided data.

    Parameters

    Returns Promise<Uint8Array>

    A Promise which will be fulfilled with the hash digest.

    Remarks

    A digest is the output of the hash function. It's a fixed-size string of bytes that uniquely represents the data input into the hash function. The digest is often used for data integrity checks, as any alteration in the input data results in a significantly different digest.

    It takes the algorithm identifier of the hash function and data to digest as input and returns the digest of the data.

    Example

    const sha2 = new Sha2Algorithm();
    const data = new TextEncoder().encode('Messsage');
    const digest = await sha2.digest({ data });