mirror of
https://github.com/nprasad2077/NBA_Go.git
synced 2026-09-22 14:05:13 +00:00
23 lines
453 B
Go
23 lines
453 B
Go
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[:]
|
||
} |