Table of Contents

About

sha256 is a hash function of the sha family

The sha256 value in a integrity HTML attribute is the sha256 value transformed in base64

openssl dgst -sha256 -binary stylesheet.css | openssl base64 -A

Tools

Javascript

  • With the crypto.subtle.digest function.
let digestMessage = async function (message) {
  const encoder = new TextEncoder();
  let data = encoder.encode(message);
  // hash
  let hashBufferArray = await crypto.subtle.digest('SHA-256', data);
  // convert buffer array to byte array
  let hashByteArray = Array.from(new Uint8Array(hashBufferArray));   
  // convert bytes to hex string  
  let hashHex = hashByteArray.map(b => b.toString(16).padStart(2, '0')).join(''); 
  console.log(hashHex);
}
document.forms[0].requestSubmit();
  • Output: Test it yourself, change the input and see the change in the hash generated

Powershell

Get-FileHash -Path hello.exe -Algorithm SHA256

sha256sum

the linux sha256sum utility.

sha256sum myFile
89829d79d0ec276abc565d258321b0eb2e6233906ee11604b34d97fbfe522956 myFile

Openssl

Openssl

openssl dgst -sha256 file
SHA256(file)= 89829d79d0ec276abc565d258321b0eb2e6233906ee11604b34d97fbfe522956