Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions internal/crypto/hmac.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package crypto

import (
"github.com/google/uuid"
"crypto/rand"
"encoding/hex"
)

// NewHMAC key returns new key that can be used to ecnrypt data using HMAC algo
// returns key, string, error
// NewHMACKey returns a new cryptographically random key for HMAC signing.
func NewHMACKey(algo, keyID string) (string, string, error) {
key := uuid.New().String()
keyBytes := make([]byte, 32)
if _, err := rand.Read(keyBytes); err != nil {
return "", "", err
}
key := hex.EncodeToString(keyBytes)
jwkPublicKey, err := GetPubJWK(algo, keyID, []byte(key))
if err != nil {
return "", "", err
Expand Down