Skip to content

Instantly share code, notes, and snippets.

@bgv
Created June 22, 2016 03:02
Show Gist options
  • Save bgv/49426372a5f7dbe6b6eb66f12900ba0c to your computer and use it in GitHub Desktop.
Save bgv/49426372a5f7dbe6b6eb66f12900ba0c to your computer and use it in GitHub Desktop.
Create base64 hash using HMAC SHA256
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