2fas-server/internal/common/crypto/prng.go

20 lines
295 B
Go
Raw Normal View History

2022-12-31 10:22:38 +01:00
package crypto
import (
"crypto/rand"
"encoding/hex"
)
func GenerateNonce() (string, error) {
bytes := make([]byte, 32)
_, err := rand.Read(bytes)
if err != nil {
return "", err
}
return hex.EncodeToString(bytes), nil
//return base64.URLEncoding.EncodeToString(nonceBytes), nil
}