mirror of
https://github.com/nprasad2077/NBA_Go.git
synced 2026-09-22 14:05:13 +00:00
api key auth added
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package security
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
)
|
||||
|
||||
// GenerateRawKey returns a 32‑byte cryptographically‑random 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 SHA‑256 hash suitable for storage.
|
||||
func HashKey(raw string) []byte {
|
||||
h := sha256.Sum256([]byte(raw))
|
||||
return h[:]
|
||||
}
|
||||
Reference in New Issue
Block a user