WhatsApp Media Decrypt icon

WhatsApp Media Decrypt

Decrypt WhatsApp media files using mediaKey with proper MAC verification

Overview

This node decrypts WhatsApp media files that are encrypted and accessible via a URL. It uses the provided base64-encoded media key (extracted from WhatsApp message metadata) to verify the integrity of the encrypted file and then decrypt it using AES-256-CBC with proper MAC verification. The node supports different types of WhatsApp media messages including audio, image, video, and document files.

Common scenarios where this node is useful include:

  • Automatically downloading and decrypting WhatsApp media attachments shared in chats for further processing or archiving.
  • Integrating WhatsApp media decryption into automated workflows that handle WhatsApp message data.
  • Converting encrypted WhatsApp media files into usable formats for analysis, storage, or forwarding.

Practical example:

  • A workflow receives WhatsApp message metadata containing an encrypted media URL and media key. This node downloads the encrypted file, verifies its authenticity, decrypts it, and outputs the decrypted media as binary data ready for saving or further use.

Properties

Name Meaning
URL URL of the encrypted WhatsApp media file (usually ends with .enc). Must be a valid non-empty string.
Media Key Base64-encoded media key used for decryption, obtained from WhatsApp message metadata. Must be a valid base64 string.
Message Type Type of WhatsApp message; must match the actual media type. Options: Audio Message (voice messages/audio files), Image Message (photos/images), Video Message (videos/GIFs), Document Message (documents/other files).
MIME Type Expected MIME type of the decrypted file. Options depend on the selected Message Type:
- For Audio Message: audio/ogg, audio/mpeg, audio/mp4, audio/wav, audio/aac
- For Image Message: image/jpeg, image/png, image/webp, image/gif
- For Video Message: video/mp4, video/webm, video/avi, video/quicktime
- For Document Message: application/pdf, text/plain, application/vnd.openxmlformats-officedocument.wordprocessingml.document (Word), application/vnd.openxmlformats-officedocument.spreadsheetml.sheet (Excel), application/vnd.openxmlformats-officedocument.presentationml.presentation (PowerPoint), application/zip, application/x-rar-compressed, application/octet-stream (binary/unknown)

Output

The node outputs an array of items, each containing:

  • json: Metadata about the decrypted file:

    • fileName: Generated filename based on message type, timestamp, and MIME type extension.
    • fileSize: Size in bytes of the decrypted file.
    • originalEncryptedSize: Size in bytes of the downloaded encrypted file.
    • messageType: The type of WhatsApp message processed.
    • mimetype: The MIME type of the decrypted file.
    • url: The original URL truncated to 100 characters for reference.
    • decryptionSuccess: Boolean indicating if decryption was successful.
    • timestamp: ISO timestamp when the operation was performed.
  • binary: Contains the decrypted media file encoded in base64 under a key matching the generated filename. Includes:

    • data: Base64 string of the decrypted file content.
    • fileName: Same as in JSON metadata.
    • mimeType: MIME type of the decrypted file.

If decryption fails and "Continue On Fail" is enabled, the output item will contain error details instead of decrypted data.

Dependencies

  • Requires internet access to download the encrypted media file from the provided URL.
  • Uses an HTTP client library to fetch the encrypted file with a custom User-Agent header mimicking WhatsApp.
  • Uses Node.js built-in crypto module for HMAC and AES-256-CBC decryption.
  • No external API keys or credentials are required beyond the media key provided by WhatsApp message metadata.

Troubleshooting

  • Common issues:

    • Invalid or empty URL or media key input.
    • Media key not properly base64 encoded.
    • Incorrect message type selection that does not match the actual media.
    • Download failures due to network issues or invalid URLs.
    • Encrypted file too small or corrupted.
    • MAC verification failure indicating possible wrong media key, wrong message type, corrupted download, or non-WhatsApp encrypted file.
  • Error messages and resolutions:

    • "URL is required and must be a non-empty string": Provide a valid URL.
    • "Media Key is required and must be a non-empty string": Provide a valid base64 media key.
    • "Media Key must be valid base64 encoded string": Check encoding of the media key.
    • "Invalid message type. Must be one of: audioMessage, imageMessage, videoMessage, documentMessage": Select correct message type.
    • "Failed to download file after 3 attempts": Check network connectivity and URL validity.
    • "Downloaded file is empty (0 bytes)" or "Downloaded file is too small": Verify the URL points to a valid encrypted WhatsApp media file.
    • "MAC verification failed...": Indicates integrity check failure; verify media key, message type, and file completeness.
    • "AES decryption failed": Could indicate corrupted data or incorrect keys.

Enabling "Continue On Fail" allows the workflow to proceed even if some items fail decryption, providing error details in output.

Links and References

Discussion