G2A Many GEOs
SHARE
TWEET

crypto-sha.js

h8rt3rmin8r Apr 7th, 2020 116 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Returns SHA-256 hash from supplied message.
  3.  *
  4.  * @param   {String} message.
  5.  * @returns {String} hash as hex string.
  6.  *
  7.  * @example
  8.  *   sha256('abc').then(hash => console.log(hash));
  9.  *   const hash = await sha256('abc');
  10.  */
  11. async function sha256(message) {
  12.     const msgUint8 = new TextEncoder('utf-8').encode(message);                      // encode as UTF-8
  13.     const hashBuffer = await crypto.subtle.digest('SHA-256', msgUint8);             // hash the message
  14.     const hashArray = Array.from(new Uint8Array(hashBuffer));                       // convert hash to byte array
  15.     const hashHex = hashArray.map(b => ('00' + b.toString(16)).slice(-2)).join(''); // convert bytes to hex string
  16.     return hashHex;
  17. }
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top