A utility class for computing BLAKE2b cryptographic hashes.

BLAKE2b is a fast, secure cryptographic hash function optimized for performance and security. It is used widely in blockchain applications and cryptographic systems for hashing arbitrary data.

Methods

Methods

  • Computes a BLAKE2b hash of the given data with the specified hash length.

    This method takes arbitrary binary data and computes its BLAKE2b hash with the specified output length. BLAKE2b supports output lengths from 1 to 64 bytes.

    Parameters

    • data: Uint8Array

      The input data to be hashed. This is a binary array representing the data.

    • hashLength: number

      The desired length of the resulting hash in bytes. Valid values are 1 to 64 bytes.

    Returns Uint8Array

    • The computed BLAKE2b hash as a binary array.
    • Throws an error if the hashing operation fails.
    const data = new TextEncoder().encode("Hello, World!");
    const hashLength = 32; // 256-bit hash
    const hash = Blake2b.computeHash(data, hashLength);
    console.log("BLAKE2b Hash:", hash);