Overview
TheCryptoManager class (core/crypto_manager.py:19) is responsible for decrypting WhatsApp backup files and managing encryption keys securely. It supports crypt12, crypt14, and crypt15 formats.
Class Definition
core/crypto_manager.py
Constructor
__init__()
Initializes the CryptoManager with secure key storage.
app_data_dir: Platform-specific application data directoryKEY_FILE: Path to encrypted keys.json filestorage_key: Machine-specific 32-byte AES keykeys: Dictionary of saved decryption keys
Core Methods
decrypt_file()
Decrypts a WhatsApp backup file using the provided hexadecimal key.
Path to the encrypted backup file (*.crypt12/14/15)
64-character hexadecimal encryption key
Path where decrypted SQLite database will be saved
True if decryption succeeded, False otherwise
- Validates input file and hex key
- Attempts crypt12 decryption (AES-GCM with simple IV)
- Derives key using HMAC-SHA256
- Tries known offset patterns from
COMMON_OFFSETS - Performs brute-force offset scanning if needed
- Decompresses with zlib
- Writes decrypted SQLite database
save_key()
Saves a decryption key securely with machine-specific encryption.
Device serial number or identifier
WhatsApp package (com.whatsapp or com.whatsapp.w4b)
64-character hexadecimal decryption key
- Keys are stored in
keys.jsonat the app data directory - File is encrypted with AES-GCM using machine-specific key
- Keys are organized by device ID and package
get_key()
Retrieves a saved decryption key for a specific device and package.
Device serial number
WhatsApp package identifier
64-character hex key if found, None otherwise
Internal Methods
_get_storage_key()
Derives a machine-specific encryption key using PBKDF2.
- Uses MAC address (
uuid.getnode()) as unique identifier - Applies PBKDF2 with 100,000 iterations
- Salt:
WhatsAppForensicTool_Storage_Salt - Output: 32-byte AES-256 key
_derive_key()
Derives the database encryption key from the raw 64-byte key using HMAC-SHA256.
- Intermediate key: HMAC-SHA256 with null key and key_stream
- Final key: HMAC-SHA256 with intermediate key and “backup encryption\x01”
_encrypt_data() / _decrypt_data()
Encrypts/decrypts key storage file using AES-GCM.
[12-byte nonce][16-byte tag][ciphertext]
_migrate_keys()
Automatically migrates plaintext keys to encrypted storage.
- Detects legacy
keys.jsonin project directory - Encrypts and moves to app data directory
- Creates backup (
.bakfile)
Constants
COMMON_OFFSETS
Known IV and database start offsets for WhatsApp backup formats.
Usage Example
Related
Decryption Guide
Learn how to decrypt WhatsApp backups
Crypt Formats
Understanding crypt12/14/15 formats
Key Management
Advanced key storage and security
Troubleshooting
Solve decryption issues
