Created
July 13, 2020 12:10
-
-
Save albarin/3ff67a2a920d6f08bb686b1c7f576af6 to your computer and use it in GitHub Desktop.
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
func verifySignature(payload []byte, secret, receivedSignature string) (bool, error) { | |
signature, err := computeSignature(payload, secret) | |
if err != nil { | |
return false, err | |
} | |
return signature == receivedSignature, nil | |
} | |
func computeSignature(payload []byte, secret string) (string, error) { | |
h := hmac.New(sha256.New, []byte(secret)) | |
_, err := h.Write(payload) | |
if err != nil { | |
return "", err | |
} | |
return "sha256=" + base64.StdEncoding.EncodeToString(h.Sum(nil)), nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment