Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Modified from https://xpertkb.com/compute-hash-string-powershell/
- ## Changed from original as MD5CryptoServiceProvider gives error "This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms"
- ## if FIPS compliant algorithms are enforced - see https://port135.com/fips-validated-cryptographic-algorithms/
- function get-hash
- {
- Param
- (
- [Parameter(Mandatory=$true,HelpMessage='String to hash')]
- [string]$textToHash
- )
- [string]$result = $null
- if( -Not [string]::IsNullOrEmpty( $textToHash ))
- {
- $hasher = $null
- $hasher = New-Object -TypeName System.Security.Cryptography.SHA256CryptoServiceProvider
- if( $hasher )
- {
- $toHash = [System.Text.Encoding]::UTF8.GetBytes( $textToHash )
- $hashByteArray = $hasher.ComputeHash( $toHash )
- foreach( $byte in $hashByteArray )
- {
- $result = "$result{0:X2}" -f $byte
- }
- }
- }
- $result ## return
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement