Last active
July 15, 2020 22:27
-
-
Save guitarrapc/482511fc0cd091408f520fa0c5c5f1da to your computer and use it in GitHub Desktop.
Compute Github Webhook SHA1 from github secret for PowerShell / C#.
This file contains 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
var target = "YOUR GITHUB WEBHOOK JSON"; | |
var key = "GITHUB WEBHOOK SECRET"; | |
var data = System.Text.Encoding.UTF8.GetBytes(target); | |
var keyData = System.Text.Encoding.UTF8.GetBytes(key); | |
using (var hmac = new System.Security.Cryptography.HMACSHA1(keyData)) | |
{ | |
var bs = hmac.ComputeHash(data); | |
var sha1 = System.BitConverter.ToString(bs).ToLower().Replace("-",""); | |
Console.WriteLine($"YOUR WEBHOOK JSON HASH (SHA1) is : {sha1}"); | |
} |
This file contains 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
# Serialize your webhook json to file, or passdirectly from data | |
$target = cat -Raw -Path .\GITHUBWEBHOOK.json; | |
# or use raw string. | |
# $target = "YOUR GITHUB WEBHOOK JSON"; | |
$key = "GITHUB WEBHOOK SECRET"; | |
$data = [System.Text.Encoding]::UTF8.GetBytes($target); | |
$keyData = [System.Text.Encoding]::UTF8.GetBytes($key); | |
$hmac = [System.Security.Cryptography.HMACSHA1]::new($keyData); | |
$bs = $hmac.ComputeHash($data); | |
$hmac.Dispose(); | |
$sha1 = [System.BitConverter]::ToString($bs).ToLower().Replace("-",""); | |
Write-Host "YOUR WEBHOOK JSON HASH (SHA1) is : $sha1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment