Created
June 22, 2016 03:02
-
-
Save bgv/49426372a5f7dbe6b6eb66f12900ba0c to your computer and use it in GitHub Desktop.
Create base64 hash using HMAC SHA256
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
package main | |
import ( | |
"crypto/hmac" | |
"crypto/sha256" | |
"encoding/base64" | |
"fmt" | |
) | |
func ComputeHmac256(message string, secret string) string { | |
key := []byte(secret) | |
h := hmac.New(sha256.New, key) | |
h.Write([]byte(message)) | |
return base64.StdEncoding.EncodeToString(h.Sum(nil)) | |
} | |
func main() { | |
fmt.Println(ComputeHmac256("Message", "secret")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment