HMAC SHA1 using PowerShell
The following bit will create a hex-formatted HMAC SHA1 hash of a “string” using a “secret”,
$hmacsha = New-Object System.Security.Cryptography.HMACSHA1
$hmacsha.key = [Text.Encoding]::ASCII.GetBytes("secret")
$signature = $hmacsha.ComputeHash([Text.Encoding]::ASCII.GetBytes("string"))
[string]::join("", ($signature | % {([int]$_).toString('x2')}))
If you look closely at the snippet itself, you’ll notice it assumes your strings are ASCII-encoded, so you may need to adjust it slightly in some cases.
By the way, the answer is ee8ac90d2d72885a4247f86addea4c3c29a4cba4.
Advertisement
Categories: Hints, PowerShell