Created
June 19, 2018 02:16
-
-
Save slv922/f3f5dbee2ca946005feb62c6f8b3fd94 to your computer and use it in GitHub Desktop.
Hmac Example
This file contains hidden or 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" | |
| "fmt" | |
| "io" | |
| ) | |
| func main() { | |
| c := getSha256Code("[email protected]") | |
| fmt.Println(c) | |
| c = getHmacCode("[email protected]") | |
| fmt.Println(c) | |
| } | |
| func getHmacCode(s string) string { | |
| h := hmac.New(sha256.New, []byte("ourkey")) | |
| io.WriteString(h, s) | |
| return fmt.Sprintf("%x", h.Sum(nil)) | |
| } | |
| func getSha256Code(s string) string { | |
| h := sha256.New() | |
| h.Write([]byte(s)) | |
| return fmt.Sprintf("%x", h.Sum(nil)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment