MCPcopy Create free account
hub / github.com/authorizerdev/authorizer / EncryptTOTPSecret

Function EncryptTOTPSecret

internal/crypto/totp.go:28–37  ·  view source on GitHub ↗

EncryptTOTPSecret encrypts the TOTP shared secret with AES-256-GCM (using the existing EncryptAES helper, which derives the key via HKDF) and prepends TOTPCipherPrefix so it is recognisable as ciphertext. TOTP secrets are long-lived — they are enrolled once per user and used forever — so a reversib

(plain, key string)

Source from the content-addressed store, hash-verified

26// forever — so a reversible primitive is required (we need the original
27// secret on every Validate call to compute the expected code).
28func EncryptTOTPSecret(plain, key string) (string, error) {
29 if plain == "" {
30 return "", nil
31 }
32 ct, err := EncryptAES(key, plain)
33 if err != nil {
34 return "", err
35 }
36 return TOTPCipherPrefix + ct, nil
37}
38
39// DecryptTOTPSecret decrypts a value previously written by
40// EncryptTOTPSecret. It is strict: the stored value MUST carry the

Calls 1

EncryptAESFunction · 0.85