Skip to content

Instantly share code, notes, and snippets.

@Wind010
Last active September 2, 2020 23:22
Show Gist options
  • Select an option

  • Save Wind010/e812631d10e963d6597bc3ae4021f98b to your computer and use it in GitHub Desktop.

Select an option

Save Wind010/e812631d10e963d6597bc3ae4021f98b to your computer and use it in GitHub Desktop.
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