Bun

Symbol

CryptoHasher.constructor

constructor (algorithm: SupportedCryptoAlgorithms, hmacKey?: string | TypedArray<ArrayBufferLike>): CryptoHasher

Create a new hasher

@param algorithm

The algorithm to use. See algorithms for a list of supported algorithms

@param hmacKey

Optional key for HMAC. Must be a string or TypedArray. If not provided, the hasher will be a non-HMAC hasher.

Referenced types

type SupportedCryptoAlgorithms = 'blake2b256' | 'blake2b512' | 'md4' | 'md5' | 'ripemd160' | 'sha1' | 'sha224' | 'sha256' | 'sha384' | 'sha512' | 'sha512-224' | 'sha512-256' | 'sha3-224' | 'sha3-256' | 'sha3-384' | 'sha3-512' | 'shake128' | 'shake256'

class CryptoHasher

Hardware-accelerated cryptographic hash functions

Used for crypto.createHash()

  • readonly algorithm: SupportedCryptoAlgorithms

    The algorithm chosen to hash the data

  • readonly byteLength: number

    The length of the output hash in bytes

  • readonly static algorithms: SupportedCryptoAlgorithms[]

    List of supported hash algorithms

    These are hardware accelerated with BoringSSL

  • Perform a deep copy of the hasher

  • digest(encoding: DigestEncoding): string

    Finalize the hash. Resets the CryptoHasher so it can be reused.

    @param encoding

    DigestEncoding to return the hash in. If none is provided, it will return a Uint8Array.

    digest(): Buffer

    Finalize the hash and return a Buffer

    digest(hashInto: TypedArray): TypedArray

    Finalize the hash

    @param hashInto

    TypedArray to write the hash into. Faster than creating a new one each time

  • update(input: BlobOrStringOrBuffer, inputEncoding?: Encoding): CryptoHasher

    Update the hash with data

  • static hash(algorithm: SupportedCryptoAlgorithms, input: BlobOrStringOrBuffer): Buffer

    Run the hash over the given data

    @param input

    string, Uint8Array, or ArrayBuffer to hash. Uint8Array or ArrayBuffer is faster.

    static hash(algorithm: SupportedCryptoAlgorithms, input: BlobOrStringOrBuffer, hashInto: TypedArray): TypedArray

    Run the hash over the given data

    @param input

    string, Uint8Array, or ArrayBuffer to hash. Uint8Array or ArrayBuffer is faster.

    @param hashInto

    TypedArray to write the hash into. Faster than creating a new one each time

    static hash(algorithm: SupportedCryptoAlgorithms, input: BlobOrStringOrBuffer, encoding: DigestEncoding): string

    Run the hash over the given data

    @param input

    string, Uint8Array, or ArrayBuffer to hash. Uint8Array or ArrayBuffer is faster.

    @param encoding

    DigestEncoding to return the hash in