mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 00:49:03 +00:00
18 lines
397 B
Go
18 lines
397 B
Go
|
|
package server
|
||
|
|
|
||
|
|
import (
|
||
|
|
"crypto/rand"
|
||
|
|
"encoding/base64"
|
||
|
|
)
|
||
|
|
|
||
|
|
// GenerateRandomText return a string generated by filling in keySize bytes with
|
||
|
|
// random data and then base64 encoding those bytes
|
||
|
|
func GenerateRandomText(keySize int) (string, error) {
|
||
|
|
key := make([]byte, keySize)
|
||
|
|
_, err := rand.Read(key)
|
||
|
|
if err != nil {
|
||
|
|
return "", err
|
||
|
|
}
|
||
|
|
return base64.StdEncoding.EncodeToString(key), nil
|
||
|
|
}
|