ps/Modules/Alkami.PowerShell.Common/Public/Get-Sha256Hash.ps1

36 lines
789 B
PowerShell
Raw Normal View History

2023-05-30 22:51:22 -07:00
function Get-Sha256Hash {
<#
.SYNOPSIS
Get the SHA-256 hash of a value
.PARAMETER Value
Value to hash
#>
[CmdletBinding()]
Param(
[string]$Value
)
[System.Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null
try {
$hash = [System.Security.Cryptography.SHA256Managed]::Create()
$enc = [System.Text.Encoding]::UTF8
$bytes = ($hash.ComputeHash($enc.GetBytes($Value)))
$machineKeySb = New-Object System.Text.StringBuilder(256)
for ($i = 0; $i -lt $bytes.Length; $i++) {
$machineKeySb.Append(("{0:X2}" -f $bytes[$i])) | Out-Null
}
return $machineKeySb.ToString()
}
finally {
if ($null -ne $hash) {
$hash.Dispose()
}
}
}