hashBrowser
Creates a hash for a value using the SHA-256 algorithm. Returns a promise.
- Use the SubtleCrypto API to create a hash for the given value.
- Create a new
TextEncoder
and use it to encodeval
, passing its value toSubtleCrypto.digest()
to generate a digest of the given data. - Use
DataView.prototype.getUint32()
to read data from the resolvedArrayBuffer
. - Add the data to an array using
Array.prototype.push()
after converting it to its hexadecimal representation usingNumber.prototype.toString(16)
. - Finally, use
Array.prototype.join()
to combine values in the array ofhexes
into a string.