PureGremlin

Get-StringHash

Sep 17th, 2021
948
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <##
  2. Source : https://community.idera.com/database-tools/powershell/powertips/b/tips/posts/generating-md5-hashes-from-text
  3. Usage : Get-StringHash "Hello World!"
  4. ##>
  5. Function Get-StringHash
  6. {
  7.     param
  8.     (
  9.         [String] $String,
  10.         $HashName = "MD5"
  11.     )
  12.     $bytes = [System.Text.Encoding]::UTF8.GetBytes($String)
  13.     $algorithm = [System.Security.Cryptography.HashAlgorithm]::Create('MD5')
  14.     $StringBuilder = New-Object System.Text.StringBuilder
  15.  
  16.     $algorithm.ComputeHash($bytes) |
  17.     ForEach-Object {
  18.         $null = $StringBuilder.Append($_.ToString("x2"))
  19.     }
  20.  
  21.     $StringBuilder.ToString()
  22. }
RAW Paste Data