When data
is a string, it will be encoded as UTF-8 before being hashed. If a different input encoding is desired for a string input, user
could encode the string into a TypedArray
using either TextEncoder
or Buffer.from()
and passing the encoded TypedArray
into this API instead.
Optional
outputEncoding: BinaryToTextEncodingEncoding used to encode the returned digest.
Optional
outputEncoding: "buffer" | BinaryToTextEncoding
A utility for creating one-shot hash digests of data. It can be faster than the object-based
crypto.createHash()
when hashing a smaller amount of data (<= 5MB) that's readily available. If the data can be big or if it is streamed, it's still recommended to usecrypto.createHash()
instead. Thealgorithm
is dependent on the available algorithms supported by the version of OpenSSL on the platform. Examples are'sha256'
,'sha512'
, etc. On recent releases of OpenSSL,openssl list -digest-algorithms
will display the available digest algorithms.Example: