Skip to content

Instantly share code, notes, and snippets.

@jiftechnify
Created October 25, 2018 13:49
Show Gist options
  • Save jiftechnify/57c6b841fcd0a3feebfbe7b7af2a76e9 to your computer and use it in GitHub Desktop.
Save jiftechnify/57c6b841fcd0a3feebfbe7b7af2a76e9 to your computer and use it in GitHub Desktop.
HMAC sample in Golang
func main() {
key := []byte("hogefugapoyopoyopoyo")
text := []byte("text")
mac1 := hmac.New(sha256.New, key)
c1 := mac1.Sum(text)
fmt.Println(c1)
fmt.Println(base64.StdEncoding.EncodeToString(c1))
mac2 := hmac.New(sha256.New, key)
mac2.Write(text)
c2 := mac2.Sum(nil)
fmt.Println(c2)
fmt.Println(base64.StdEncoding.EncodeToString(c2))
eq := hmac.Equal(c1, c2)
fmt.Println("result: ", eq)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment