mirror of
https://github.com/skyle1995/NetworkAuth.git
synced 2026-05-25 02:24:05 +08:00
Add classification annotations
This commit is contained in:
@@ -7,6 +7,10 @@ import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// ============================================================================
|
||||
// 公共函数
|
||||
// ============================================================================
|
||||
|
||||
// GenerateSecureJWTSecret 生成安全的JWT密钥
|
||||
// 生成64字节(512位)的随机密钥,使用base64编码
|
||||
func GenerateSecureJWTSecret() (string, error) {
|
||||
@@ -15,7 +19,7 @@ func GenerateSecureJWTSecret() (string, error) {
|
||||
if _, err := rand.Read(bytes); err != nil {
|
||||
return "", fmt.Errorf("生成JWT密钥失败: %w", err)
|
||||
}
|
||||
|
||||
|
||||
// 使用base64编码,便于配置文件存储
|
||||
return base64.StdEncoding.EncodeToString(bytes), nil
|
||||
}
|
||||
@@ -28,7 +32,7 @@ func GenerateSecureEncryptionKey() (string, error) {
|
||||
if _, err := rand.Read(bytes); err != nil {
|
||||
return "", fmt.Errorf("生成加密密钥失败: %w", err)
|
||||
}
|
||||
|
||||
|
||||
// 使用十六进制编码
|
||||
return hex.EncodeToString(bytes), nil
|
||||
}
|
||||
@@ -39,11 +43,11 @@ func GenerateSecureKeys() (jwtSecret, encryptionKey string, err error) {
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
|
||||
encryptionKey, err = GenerateSecureEncryptionKey()
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
|
||||
return jwtSecret, encryptionKey, nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user