sha

This tag uses the browsers crypto API to perform a hash operation using various algorithms

Created by: hackvertor
Installed 1 times

Category: Hash

Created on: Monday, September 16, 2024 at 8:21:11 PM

Updated on: Monday, September 16, 2024 at 8:21:11 PM

This is a built in tag

Tag arguments
[
   {
      "type": "quotelessString",
      "help": "This argument chooses the hash algorithm to use: SHA-1, SHA-256, SHA-384, SHA-512",
      "defaultValue": "SHA-256"
   }
]
Code
class sha {
  async encode(input, algo) {
    const encoder = new TextEncoder();
    const data = encoder.encode(input);
    const hashBuffer = await crypto.subtle.digest(algo, data);
    const hashArray = Array.from(new Uint8Array(hashBuffer)); 
    const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); 
    return hashHex;
  }
}