36 lines
789 B
PowerShell
36 lines
789 B
PowerShell
|
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()
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|