Private/ConvertTo-SFCheckIdV1Hash.ps1

function ConvertTo-SFCheckIdV1Hash {
    [CmdletBinding()]
    [OutputType([string])]
    param (
        [Parameter(Mandatory)]
        [AllowEmptyString()]
        [string]$Value
    )

    if ($Value.Length -eq 0) {
        throw 'CheckID-v1 cannot hash an empty national ID.'
    }

    # CheckID-v1 hashes the exact UTF-8 string value. Each subsequent iteration
    # hashes the uppercase hexadecimal text produced by the preceding iteration.
    $currentValue = $Value
    $sha256 = [System.Security.Cryptography.SHA256]::Create()

    try {
        for ($iteration = 0; $iteration -lt 2000; $iteration++) {
            $bytes = [System.Text.Encoding]::UTF8.GetBytes($currentValue)
            $hashBytes = $sha256.ComputeHash($bytes)
            $currentValue = [System.BitConverter]::ToString($hashBytes).Replace('-', '')
        }
    }
    finally {
        $sha256.Dispose()
    }

    return $currentValue
}