feat: integration v2 and API key PART 1/3

This commit is contained in:
fsylvain committed 2026-10-04 21:56:14 +02:00
1 parent 7e9bd9ba30
commit 844842fdae
40 files changed
+3782 -64

No files matched your search

@@ -0,0 +1,34 @@
package hashing
import (
"RenewCMS/internal/domain/apikey"
"crypto/rand"
"crypto/sha256"
"encoding/base64"
"encoding/hex"
)
const (
apiKeyRandomBytes = 32
apiKeyPrefixLen = 12
)
type SHA256KeyGenerator struct{}
func NewSHA256KeyGenerator() *SHA256KeyGenerator {
return &SHA256KeyGenerator{}
}
func (g *SHA256KeyGenerator) Generate() (string, string, string) {
random := make([]byte, apiKeyRandomBytes)
_, _ = rand.Read(random)
rawKey := apikey.RawKeyPrefix + base64.RawURLEncoding.EncodeToString(random)
return rawKey, rawKey[:apiKeyPrefixLen], g.Hash(rawKey)
}
func (g *SHA256KeyGenerator) Hash(rawKey string) string {
sum := sha256.Sum256([]byte(rawKey))
return hex.EncodeToString(sum[:])
}
var _ apikey.KeyGenerator = &SHA256KeyGenerator{}