mirror of
https://github.com/sipeed/NanoKVM.git
synced 2026-09-11 00:22:56 -05:00
22 lines
402 B
Go
22 lines
402 B
Go
package config
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"encoding/base64"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
// Generate random string for secret key.
|
|
func generateRandomSecretKey() string {
|
|
b := make([]byte, 64)
|
|
_, err := rand.Read(b)
|
|
if err != nil {
|
|
currentTime := time.Now().UnixNano()
|
|
timeString := fmt.Sprintf("%d", currentTime)
|
|
return fmt.Sprintf("%064s", timeString)
|
|
}
|
|
|
|
return base64.URLEncoding.EncodeToString(b)
|
|
}
|