DriveLinked/pkg/utils/key.go

21 lines
332 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package utils
import (
"crypto/rand"
"encoding/hex"
"github.com/kataras/golog"
)
// NewKey 生成Key
func NewKey() string {
length := 48
// HS256的key其实就是个随机字符串生成器
key := make([]byte, length/2)
_, err := rand.Read(key)
if err != nil {
golog.Fatal(err)
}
return hex.EncodeToString(key)
}