github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/pkg/secrets/secrets.go (about) 1 package secrets 2 3 import ( 4 "crypto/rand" 5 "encoding/hex" 6 ) 7 8 // TokenBytes returns a secure random token of the specified number of bytes 9 func TokenBytes(nbytes uint8) ([]byte, error) { 10 token := make([]byte, nbytes) 11 _, err := rand.Read(token) 12 return token, err 13 } 14 15 // TokenHex returns a secure random token of the specified number of bytes, encoded as hex 16 func TokenHex(nbytes uint8) (string, error) { 17 tokenBytes, err := TokenBytes(nbytes) 18 return hex.EncodeToString(tokenBytes), err 19 }