To export a hash in javascript, you can use the Web Crypto API to create a hash of your data, then export it as a base64-encoded string. Here's an example:
index.tsx262 chars7 lines
In this example, we use the crypto.subtle.digest
method to generate a SHA-256 hash of the string 'hello world'. The result is a buffer of bytes which we then convert to a base64-encoded string using the btoa
method.
Note that the crypto.subtle.digest
method returns a Promise, so we use the await
keyword to wait for the result before continuing. Also, the btoa
method expects a string of characters, so we need to convert the byte buffer to an array of integers using the spread operator (...
) and String.fromCharCode
.
gistlibby LogSnag