kdbxtool.security.totp¶
TOTP (Time-based One-Time Password) implementation per RFC 6238.
This module provides TOTP code generation from otpauth:// URIs stored in KeePass entry otp fields.
Functions
|
Generate a TOTP code. |
|
Parse KeePassXC legacy TOTP fields. |
|
Parse an otpauth:// URI into a TotpConfig. |
Classes
|
A generated TOTP code with expiration info. |
|
TOTP configuration parsed from an otpauth:// URI. |
- class kdbxtool.security.totp.TotpCode(code, period, generated_at)[source]¶
Bases:
objectA generated TOTP code with expiration info.
- class kdbxtool.security.totp.TotpConfig(secret, digits=6, period=30, algorithm='SHA1', issuer=None, account=None)[source]¶
Bases:
objectTOTP configuration parsed from an otpauth:// URI.
- Parameters:
- algorithm¶
Hash algorithm (SHA1, SHA256, or SHA512)
- Type:
Literal[‘SHA1’, ‘SHA256’, ‘SHA512’]
- kdbxtool.security.totp.parse_otpauth_uri(uri)[source]¶
Parse an otpauth:// URI into a TotpConfig.
- Supports the standard otpauth:// URI format:
otpauth://totp/LABEL?secret=BASE32SECRET&issuer=ISSUER&…
- Parameters:
uri (str) – The otpauth:// URI string
- Returns:
TotpConfig with parsed parameters
- Raises:
ValueError – If the URI is invalid or missing required parameters
- Return type:
- kdbxtool.security.totp.parse_keepassxc_legacy(seed, settings=None)[source]¶
Parse KeePassXC legacy TOTP fields.
KeePassXC historically stored TOTP in separate custom fields: - “TOTP Seed”: Base32 secret - “TOTP Settings”: “period;digits” (e.g., “30;6”)
- Parameters:
- Returns:
TotpConfig with parsed parameters
- Return type:
- kdbxtool.security.totp.generate_totp(config, timestamp=None)[source]¶
Generate a TOTP code.
- Parameters:
config (TotpConfig) – TOTP configuration
timestamp (float | None) – Unix timestamp (defaults to current time)
- Returns:
TotpCode with code string and expiration info
- Return type: