Skip to content

Instantly share code, notes, and snippets.

@joeke80215
Created August 9, 2019 01:20
Show Gist options
  • Save joeke80215/cbc9080a2093a8574c7cf064c2674691 to your computer and use it in GitHub Desktop.
Save joeke80215/cbc9080a2093a8574c7cf064c2674691 to your computer and use it in GitHub Desktop.
generate random string with golang
package auth
import (
"crypto/hmac"
"crypto/rand"
"crypto/sha256"
"encoding/hex"
"log"
)
func genHash() string {
b := make([]byte, 16)
if _, err := rand.Read(b); err != nil {
log.Panic(err)
}
return hex.EncodeToString(
hmac.New(sha256.New, b).
Sum(b),
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment