Created
August 3, 2017 05:15
-
-
Save footballqq/338ef96048419ba3e3ccfb86cb43d9d0 to your computer and use it in GitHub Desktop.
windows powerscript string hash md5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#https://gallery.technet.microsoft.com/scriptcenter/Get-StringHash-aa843f71 | |
#add Param and output to the function above source. | |
#usage .\Get-StringHash "My String to hash" "MD5" | |
#also a file hash in the sourcebelow | |
#http://jongurgul.com/blog/get-stringhash-get-filehash/ | |
#how to enable excute ps in win10 | |
#https://www.tenforums.com/tutorials/54585-change-powershell-script-execution-policy-windows-10-a.html | |
#simple: Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force | |
Param | |
( | |
[Parameter(Mandatory = $true)] | |
[String]$Word, | |
[String]$Algo | |
) | |
Function Get-StringHash([String] $String,$HashName = "MD5") | |
{ | |
$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() | |
Write-Output $StringBuilder | |
#Write-Output "aaa" | |
} | |
Get-StringHash $Word $Algo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment