SHA-256 Hashing


Algorithm Explanation:

The SHA-256 hash function is a cryptographic algorithm that takes an input string and produces a fixed-size 256-bit hash value.

It operates by processing the input in blocks and applying a series of complex mathematical and logical operations, resulting in a unique hash for each input.

This example uses the Web Crypto API to perform the SHA-256 hashing, a widely adopted standard for secure hashing.

1. Convert the input text to binary data:
• Use the TextEncoder to convert the input text into binary data.

2. Use the Web Crypto API to perform SHA-256 hashing:
• Utilize the crypto.subtle.digest function from the Web Crypto API to execute the SHA-256 hashing on the binary data obtained from the previous step.

3. Convert the hash result to a hexadecimal string:
• Convert the resulting hash value, typically represented as a byte array, into a hexadecimal string using hexadecimal conversion operations.

Message: abc
Hash: ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad

Note SHA-256 hash of ‘abc’ should be: ba7816bf­8f01cfea­414140de­5dae2223­b00361a3­96177a9c­b410ff61­f20015ad