title: How to get sha256 hash output as binary data instead of hex using powershell?
body: <p>Is there an in-built method to generate SHA256 as a binary data for a given string ? Basically, I am using below bash script to first generate a hash as a binary data and then do a base64 encoding. All I want to have is the exact thing in Powershell so that both the outputs are identical:</p>
  
  <pre><code>clearString="test"
  payloadDigest=`echo -n "$clearString" | openssl dgst -binary -sha256 | openssl base64 `
  echo ${payloadDigest}
  </code></pre>
  
  <p>In powershell, I can get the SHA256 in hex using the below script, but then struggling to get it as a binary data:</p>
  
  <pre><code>$ClearString= "test"
  $hasher = [System.Security.Cryptography.HashAlgorithm]::Create('sha256')
  $hash = $hasher.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($ClearString))
  
  $hashString = [System.BitConverter]::ToString($hash)
  $256String= $hashString.Replace('-', '').ToLower()
  $sha256String="(stdin)= "+$256String
  $sha256String
  
  </code></pre>
  
  <p>I can then use [Convert]::ToBase64String($Bytes) to convert to base64 but in between how do I get a binary data similar to bash output before I pass it to base64 conversion.</p>