Created
June 13, 2025 08:36
-
-
Save vernak2539/28e93938528c67eb4eb34e3902f710c7 to your computer and use it in GitHub Desktop.
HMAC Generator
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
package main | |
import ( | |
"crypto/hmac" | |
"crypto/sha256" | |
"fmt" | |
"os" | |
) | |
// GenerateHMACSignature generates an HMAC-SHA256 signature for webhook validation | |
// secret: the webhook secret key | |
// sequenceGUID: the sequence GUID from the X-Deliveroo-Sequence-Guid header | |
// jsonBody: the JSON request body as bytes | |
func GenerateHMACSignature(secret, sequenceGUID string, jsonBody []byte) string { | |
h := hmac.New(sha256.New, []byte(secret)) | |
h.Write([]byte(sequenceGUID)) | |
h.Write([]byte(" ")) | |
h.Write(jsonBody) | |
return fmt.Sprintf("%x", h.Sum(nil)) | |
} | |
func main() { | |
if len(os.Args) != 4 { | |
fmt.Fprintf(os.Stderr, "Usage: %s <secret> <sequence-guid> <json-body>\n", os.Args[0]) | |
fmt.Fprintf(os.Stderr, "Example: %s my-secret-key abc-123-def '{\"test\":\"data\"}'\n", os.Args[0]) | |
os.Exit(1) | |
} | |
secret := os.Args[1] | |
sequenceGUID := os.Args[2] | |
jsonBody := os.Args[3] | |
signature := GenerateHMACSignature(secret, sequenceGUID, []byte(jsonBody)) | |
fmt.Println(signature) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment