Created
August 9, 2019 01:20
-
-
Save joeke80215/cbc9080a2093a8574c7cf064c2674691 to your computer and use it in GitHub Desktop.
generate random string with golang
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 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