create a blake2b hash from a string in javascript

To create a Blake2b hash from a string in JavaScript, we can use the blakejs library. First, we need to install the library using npm:

index.tsx
npm install blakejs
20 chars
2 lines

Then, we can use the library to create a Blake2b hash as follows:

index.tsx
const blake = require('blakejs');

const stringToHash = 'hello world';
const hash = blake.blake2bHex(stringToHash);

console.log(hash); // prints '5e6a406f616e587c34d08b5a8ab31a0eb85c50d2e9c8f0f695cd7b01ca6922f2c445c8d6b2937ccf40fbcc568768eddcc0dba13858af14d63853f3644b4d4e8'
276 chars
7 lines

In the code above, we require the blakejs library and define a string to hash. We then use the blake2bHex function from the library to create a Blake2b hash of the string. The blake2bHex function returns the hash in hexadecimal format as a string. We can then print the hash using console.log.

gistlibby LogSnag