Last active
September 2, 2020 23:22
-
-
Save Wind010/e812631d10e963d6597bc3ae4021f98b to your computer and use it in GitHub Desktop.
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
| param( | |
| [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$false)] | |
| [string] | |
| $secret, | |
| [Parameter(Mandatory=$true, Position=1, ValueFromPipeline=$false)] | |
| [string] | |
| $message | |
| ) | |
| # When this logic is called from Function and returned, the hash differs... | |
| [Byte[]] $key = [System.Text.Encoding]::UTF8.GetBytes($secret) | |
| [Byte[]] $messageBytes = [Text.Encoding]::ASCII.GetBytes($message) | |
| #$hmacSha = [System.Security.Cryptography.HMACSHA256]::Create() | |
| $hmacSha = New-Object System.Security.Cryptography.HMACSHA256 | |
| $hmacSha.Key = $key | |
| $signature = $hmacSha.ComputeHash($messageBytes) | |
| # Hexidecimal string | |
| [string] $hash = [System.BitConverter]::ToString($signature) | |
| $hash = $hash.Replace('-', '').ToLowerInvariant() | |
| $hash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment