api key auth added

This commit is contained in:
Ravi Prasad
2025-05-08 00:32:49 -05:00
parent 09d81c251a
commit 8c577b441c
17 changed files with 345 additions and 61 deletions
+23
View File
@@ -0,0 +1,23 @@
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[:]
}