-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNew-HashString.ps1
More file actions
45 lines (35 loc) · 1.5 KB
/
New-HashString.ps1
File metadata and controls
45 lines (35 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
function New-HashString {
<#
.SYNOPSIS
Compute has from input value and return encoded Base64 string.
.DESCRIPTION
Compute has from input value and return encoded Base64 string.
.PARAMETER Value
Specify a Base64 encoded value for which a hash will be computed.
.NOTES
Author: Nickolaj Andersen
Contact: @NickolajA
Created: 2021-08-23
Updated: 2021-08-23
Version history:
1.0.0 - (2021-08-23) Function created
#AzureToTheMax was here - this function does not appear to be used anywhere? If it is, it may need to be updated to accept a full PEM and use the X502 class like the others.
#>
param(
[parameter(Mandatory = $true, HelpMessage = "Specify a Base64 encoded value for which a hash will be computed.")]
[ValidateNotNullOrEmpty()]
[string]$Value
)
Process {
# Convert from Base64 string to byte array
$DecodedBytes = [System.Convert]::FromBase64String($Value)
# Construct a new SHA256Managed object to be used when computing the hash
$SHA256Managed = New-Object -TypeName "System.Security.Cryptography.SHA256Managed"
# Compute the hash
[byte[]]$ComputedHash = $SHA256Managed.ComputeHash($DecodedBytes)
# Convert computed hash to Base64 string
$ComputedHashString = [System.Convert]::ToBase64String($ComputedHash)
# Handle return value
return $ComputedHashString
}
}