Skip to content

Instantly share code, notes, and snippets.

@tsmolka
Last active November 15, 2017 14:43
Show Gist options
  • Select an option

  • Save tsmolka/60c0ed9d79dad5dbfb4d2dcff64eb0bf to your computer and use it in GitHub Desktop.

Select an option

Save tsmolka/60c0ed9d79dad5dbfb4d2dcff64eb0bf to your computer and use it in GitHub Desktop.
Function Get-StringHash {
Param (
[Parameter(ValueFromPipeline)][String[]]$String,
[ValidateSet('MD5','RIPEMD160','SHA1','SHA256','SHA384','SHA512')]$HashName = 'SHA256'
)
Process {
$StringBuilder = New-Object System.Text.StringBuilder
[System.Security.Cryptography.HashAlgorithm]::Create($HashName).ComputeHash([System.Text.Encoding]::UTF8.GetBytes($String)) | %{
[Void]$StringBuilder.Append($_.ToString("x2"))
}
$StringBuilder.ToString()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment