photoprism/pkg/rnd/bytes.go
Michael Mayer b32a970aab Auth: Add RandomBytes() to generate secure random bytes #98 #782
Signed-off-by: Michael Mayer <michael@photoprism.app>
2022-09-28 13:38:08 +02:00

13 lines
240 B
Go

package rnd
import "crypto/rand"
// RandomBytes returns cryptographically secure random bytes.
func RandomBytes(n int) ([]byte, error) {
b := make([]byte, n)
_, err := rand.Read(b)
if err != nil {
return nil, err
}
return b, nil
}