Skip to content

Instantly share code, notes, and snippets.

@slv922
Created June 19, 2018 02:16
Show Gist options
  • Select an option

  • Save slv922/f3f5dbee2ca946005feb62c6f8b3fd94 to your computer and use it in GitHub Desktop.

Select an option

Save slv922/f3f5dbee2ca946005feb62c6f8b3fd94 to your computer and use it in GitHub Desktop.
Hmac Example
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