DecryptTOTPSecret decrypts a value previously written by EncryptTOTPSecret. It is strict: the stored value MUST carry the TOTPCipherPrefix marker. Callers handling a row written by an older release should detect ErrTOTPSecretNotEncrypted and treat the raw stored value as a legacy base32 secret.
(stored, key string)
| 42 | // release should detect ErrTOTPSecretNotEncrypted and treat the raw |
| 43 | // stored value as a legacy base32 secret. |
| 44 | func DecryptTOTPSecret(stored, key string) (string, error) { |
| 45 | if !strings.HasPrefix(stored, TOTPCipherPrefix) { |
| 46 | return "", ErrTOTPSecretNotEncrypted |
| 47 | } |
| 48 | return DecryptAES(key, strings.TrimPrefix(stored, TOTPCipherPrefix)) |
| 49 | } |
| 50 | |
| 51 | // IsEncryptedTOTPSecret reports whether the stored value carries the |
| 52 | // TOTPCipherPrefix marker. Used by the totp authenticator's lazy |