WhatsApp Decryption
AI-generatedOverview
This node decrypts WhatsApp encrypted media files (.enc) using a provided media key and verifies the integrity of the files if requested. It downloads the encrypted file from a given URL, derives the necessary cryptographic keys, verifies the file's MAC and SHA256 hashes, decrypts the content, and outputs the decrypted file as binary data. This node is useful for workflows that handle WhatsApp media messages, enabling access to the original media content for further processing or storage.
Use Case Examples
- Decrypting an encrypted WhatsApp image file received via webhook to save it in its original format.
- Verifying and decrypting WhatsApp document files for automated processing in a document management system.
Properties
| Name | Meaning |
|---|---|
| Encrypted File URL | URL of the WhatsApp encrypted media file (.enc) to download and decrypt. |
| Media Key | Base64 encoded decryption key obtained from the WhatsApp webhook used to derive cryptographic keys for decryption. |
| MIME Type | Original MIME type of the file to correctly handle and label the decrypted output. |
| File Name | Original file name to assign to the decrypted file output. |
| Binary Property Name | Name of the binary data property in the output where the decrypted file data will be stored. |
| Verify Integrity | Boolean flag to enable or disable verification of file integrity using SHA256 hashes from the input data. |
Output
Binary
Contains the decrypted file data encoded in base64 under the specified binary property name.
JSON
fileName- Original file name of the decrypted media.mimeType- MIME type of the decrypted file.fileSize- Size in bytes of the decrypted file content.verified- Boolean indicating if the file integrity verification was successful.decryptedAt- Timestamp when the file was decrypted.error- Error message if decryption failed (present only on failure).
Dependencies
- Requires internet access to download the encrypted file from the provided URL.
- Uses cryptographic functions from Node.js 'crypto' module for key derivation, HMAC, and AES decryption.
Troubleshooting
- Download failure due to expired or invalid URL may result in receiving an HTML error page instead of the encrypted file. Check the URL validity and expiration.
- Media key length must be exactly 32 bytes after base64 decoding; otherwise, decryption will fail. Verify the media key is correctly copied from the webhook.
- SHA256 hash mismatches during encrypted file or decrypted file verification indicate data corruption or incorrect keys. Ensure the correct media key and file URL are used.
- MAC verification failure suggests the media key or file content does not match. Double-check inputs and retry.
- If the file size is unexpectedly small, it may indicate a download error or invalid file. Inspect the file content preview for HTML or error messages.
Links
- WhatsApp Cloud API Media Webhooks - Official documentation on WhatsApp media message webhooks and media key usage.
- HKDF (HMAC-based Extract-and-Expand Key Derivation Function) - Explanation of the key derivation function used to derive cryptographic keys from the media key.
- Node.js Crypto Module - Documentation for the cryptographic functions used for decryption and verification.