How to get sha256 hash output as binary data instead of hex using powershell?
I think you are over-doing this, since the ComputeHash method already returns a Byte[]
array (binary data). To do what (I think) you are trying to achieve, don't convert the bytes to string, because that will result in a hexadecimal string.
$ClearString= "test"$hasher = [System.Security.Cryptography.HashAlgorithm]::Create('sha256')$hash = $hasher.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($ClearString))# $hash is a Byte[] array# convert to Base64[Convert]::ToBase64String($hash)
returns
n4bQgYhMfWWaL+qgxVrQFaO/TxsrC4Is0V1sFbDwCgg=