Skip to content

Instantly share code, notes, and snippets.

@edwinlab
Created February 10, 2019 04:05
Show Gist options
  • Save edwinlab/335011e1e20ac72445d687539d4f004c to your computer and use it in GitHub Desktop.
Save edwinlab/335011e1e20ac72445d687539d4f004c to your computer and use it in GitHub Desktop.
package main
import (
"crypto/hmac"
"crypto/sha256"
"encoding/base64"
"encoding/hex"
)
func main() {
secret := []byte("the shared secret key here")
message := []byte("the message to hash here")
hash := hmac.New(sha256.New, secret)
hash.Write(message)
// to lowercase hexits
hex.EncodeToString(hash.Sum(nil))
// to base64
base64.StdEncoding.EncodeToString(hash.Sum(nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment