Overview
Thedpapi module provides structures and functions for working with Windows Data Protection API (DPAPI) encrypted data, master keys, credentials, and vault files.
Core Concepts
- Master Keys: Encryption keys protected by user passwords or domain keys
- DPAPI Blobs: Encrypted data containers with metadata
- Credential Files: Stored credentials encrypted with DPAPI
- Vault Files: Windows Credential Manager storage
- Domain Keys: RSA keys for domain-based DPAPI
Master Key Operations
MasterKeyFile
Container for master key metadata.Structure
- Version: File format version
- Guid: Unique identifier for the master key
- Flags: Protection flags
- Policy: Key policy settings
- MasterKeyLen: Length of master key data
- BackupKeyLen: Length of backup key data
- CredHistLen: Length of credential history
- DomainKeyLen: Length of domain key data
MasterKey
Encrypted master key that can be decrypted with user credentials.decrypt()
Decrypt the master key using derived key.Parameters
- key (bytes): Derived encryption key
Returns
64-byte decrypted master key or None if decryption failsDPAPI Blob Decryption
DPAPI_BLOB
Encrypted data blob with metadata.decrypt()
Decrypt DPAPI blob using master key.Parameters
- key (bytes): Decrypted master key
- entropy (bytes): Optional entropy data (default: None)
Returns
Decrypted cleartext data or None if verification failsKey Derivation
deriveKeysFromUser()
Derive DPAPI keys from user password.Parameters
- sid (str): User SID in canonical format
- password (str): User password
Returns
List of derived keys (SHA1, MD4, Protected Users)deriveKeysFromUserkey()
Derive DPAPI keys from password hash.Credential Structures
CREDENTIAL_BLOB
Stored credential from Windows Credential Manager.CredentialFile
Container for credential blobs.Credential History
CREDHIST_FILE
Password history for master key protection.CREDHIST_ENTRY
Single credential history entry.Vault Operations
VAULT_VCRD
Vault credential record.VAULT_VPOL
Vault policy containing encryption keys.VAULT_VPOL_KEYS
Decrypted vault AES keys.Known Vault Schemas
VAULT_INTERNET_EXPLORER
Internet Explorer/Edge credentials.VAULT_WIN_BIO_KEY
Windows Hello biometric key.Domain DPAPI
DPAPI_DOMAIN_RSA_MASTER_KEY
Domain-backed master key.PRIVATE_KEY_BLOB
RSA private key in Windows format.Encryption Algorithms
ALGORITHMS Enum
Supported cryptographic algorithms.Complete Examples
Decrypt Master Key
Decrypt DPAPI Blob
Extract Vault Credentials
Security Considerations
- Protect decrypted keys - Master keys provide access to all user data
- Secure password storage - Passwords used for key derivation
- Verify signatures - DPAPI blobs include HMAC signatures
- Handle errors - Decryption can fail with wrong keys
- Clear sensitive data - Overwrite keys and passwords after use