Skip to content

Instantly share code, notes, and snippets.

@zola-25
Created April 30, 2023 07:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zola-25/4da0aea2421c1b11a16c5d265416bb98 to your computer and use it in GitHub Desktop.
Save zola-25/4da0aea2421c1b11a16c5d265416bb98 to your computer and use it in GitHub Desktop.
PowerShell example showing outputs generated for a simple SHA-256 hash. No salting or other security mechanisms included.
$inputString = "Password123"
$sha256 = [System.Security.Cryptography.SHA256]::Create()
$bytes = [System.Text.Encoding]::UTF8.GetBytes($inputString)
$hashBytes = $sha256.ComputeHash($bytes)
$base64String = [System.Convert]::ToBase64String($hashBytes)
$binaryString = [System.Text.StringBuilder]::new()
foreach ($byte in $hashBytes) {
$binaryString.Append([Convert]::ToString($byte, 2).PadLeft(8, '0'))
}
Write-Output "`nHash of $inputString in 256 bit binary: $binaryString"
Write-Output "`nHash of $inputString in base64: $base64String"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment