File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ function Get-StringHash {
2+ <#
3+ . SYNOPSIS
4+ Returns hash from a string
5+
6+ . DESCRIPTION
7+ Returns hash from an input string using given hash algorithm.
8+ Default algorithm is: 'MD5'
9+
10+ . PARAMETER String
11+ String to be hashed
12+
13+ . PARAMETER HashName
14+ Hash algorithm name
15+
16+ . EXAMPLE
17+ Get-StringHash "test"
18+ Returns hash from string 'test'
19+
20+ . EXAMPLE
21+ Get-StringHash 'test' -HashName "sha256"
22+ Returns hash from string 'test' using 'sha256' algorithm
23+
24+ #>
25+
26+ [CmdletBinding ()]
27+ param (
28+ [Parameter (Mandatory = $true , Position = 0 )]
29+ [String ]$String ,
30+ [Parameter (Mandatory = $false , Position = 1 )]
31+ [String ]$HashName = " MD5"
32+ )
33+
34+ process {
35+ $StringBuilder = New-Object System.Text.StringBuilder
36+ [System.Security.Cryptography.HashAlgorithm ]::Create($HashName ).ComputeHash([System.Text.Encoding ]::UTF8.GetBytes($String )) | % {
37+ [Void ]$StringBuilder.Append ($_.ToString (" x2" ))
38+ }
39+ $StringBuilder.ToString ()
40+ }
41+ }
You can’t perform that action at this time.
0 commit comments