Files
NBA_Go/utils/security/api_key.go
T
2025-05-08 00:32:49 -05:00

23 lines
453 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 security
import (
"crypto/rand"
"crypto/sha256"
"encoding/hex"
)
// GenerateRawKey returns a 32byte cryptographicallyrandom string
func GenerateRawKey() (string, error) {
b := make([]byte, 32)
_, err := rand.Read(b)
if err != nil {
return "", err
}
return hex.EncodeToString(b), nil
}
// HashKey returns the SHA256 hash suitable for storage.
func HashKey(raw string) []byte {
h := sha256.Sum256([]byte(raw))
return h[:]
}