Created
October 25, 2018 13:49
-
-
Save jiftechnify/57c6b841fcd0a3feebfbe7b7af2a76e9 to your computer and use it in GitHub Desktop.
HMAC sample in Golang
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 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