Skip to content

Instantly share code, notes, and snippets.

@jimbrig
Forked from zola-25/PasswordHashingExample.ps1
Created November 7, 2024 23:28
Show Gist options
  • Save jimbrig/28e45812acfb1ddefdd2bd883c6733f0 to your computer and use it in GitHub Desktop.
Save jimbrig/28e45812acfb1ddefdd2bd883c6733f0 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