whatsapp-media-decrypt

Custom n8n node for decrypting WhatsApp encrypted media files (.enc)

Package Information

Released: 7/10/2025
Downloads: 27 weeklyĀ /Ā 46 monthly
Latest Version: 1.2.0
Author: Your Name

Documentation

WhatsApp Media Decrypt - n8n Custom Node

A custom n8n node for decrypting WhatsApp encrypted media files (.enc) using mediaKey.

Package Name: n8n-nodes-whatsapp-media-decrypt

šŸ”§ Available Decryption Methods

1. Auto (Try All Methods) - Default

Automatically tries all available methods until one succeeds:

  • HKDF Library (External HKDF library)
  • Baileys Library (@whiskeysockets/baileys library)
  • Standard Algorithm (Internal algorithm)

2. HKDF Library

Uses an external specialized HKDF library for more accurate results.

3. Baileys Library

Uses the popular @whiskeysockets/baileys library for WhatsApp bot development.

4. Standard Algorithm

The internal algorithm developed in-house.

🧱 What is this Extension?

This is a custom node for n8n that allows you to automatically decrypt WhatsApp encrypted media files using the media key (mediaKey). The extension works with all types of WhatsApp media files such as:

  • Audio Messages
  • Video Messages
  • Image Messages
  • Document Messages
  • Sticker Messages

šŸ“‹ Requirements

  • Node.js 18+
  • n8n framework
  • Media key (mediaKey) for the encrypted file
  • Encrypted file URL (.enc)

Important Note: This project requires the n8n framework. The n8n-workflow and n8n-core modules are available as peerDependencies and will be available when running the project within the n8n environment.

šŸš€ Installation

Installing as Custom Node in Existing n8n

  1. Copy the WhatsAppDecrypt folder to the nodes folder in your n8n project:

    n8n/packages/nodes-base/nodes/WhatsAppDecrypt/
    
  2. Add the required libraries to package.json:

    {
      "dependencies": {
        "axios": "^1.6.0",
        "@whiskeysockets/baileys": "^6.0.0",
        "hkdf": "^0.0.2"
      }
    }
    
  3. Build the project:

    npm run build
    

Installing as Standalone Package

  1. Clone this project:

    git clone <repository-url>
    cd n8n-nodes-whatsapp-media-decrypt
    
  2. Install libraries:

    npm install
    
  3. Build the project:

    npm run build
    
  4. Link the package with n8n:

    npm link
    cd /path/to/your/n8n
    npm link n8n-nodes-whatsapp-media-decrypt
    

šŸ› ļø How to Use

Required Inputs:

  1. Media URL (Required): URL of the encrypted WhatsApp media file (.enc)
  2. Media Key (Required): Media key for decryption (base64 encoded)
  3. Media Type (Required): Message type (audioMessage, videoMessage, etc.)
  4. Output Format (Optional): Output format (Binary Data or Base64 String)
  5. File Extension (Optional): Required file extension
  6. Decryption Method (Optional): Choose decryption method (Auto, HKDF, Baileys, Standard)

Outputs:

  • Binary Data: Decrypted file as binary data (default)
  • Base64 String: Decrypted file as base64 string
  • Metadata: Additional file information (size, timestamp, etc.)

Usage Example:

// In n8n workflow
{
  "url": "https://example.com/encrypted-media.enc",
  "mediaKey": "base64-encoded-media-key",
  "mediaType": "audioMessage",
  "outputFormat": "binary",
  "fileExtension": ".ogg",
  "decryptionMethod": "auto"
}

šŸ“ Project Structure

src/
ā”œā”€ā”€ nodes/
│   └── WhatsAppDecrypt/
│       ā”œā”€ā”€ WhatsAppDecrypt.node.ts
│       ā”œā”€ā”€ logo.svg
│       └── whatsapp.svg
ā”œā”€ā”€ utils/
│   ā”œā”€ā”€ decrypt.ts
│   ā”œā”€ā”€ decrypt-baileys.ts
│   └── decrypt-hkdf.ts
└── index.ts

šŸ”§ Development

Development Commands:

# Build project
npm run build

# Development with watch mode
npm run dev

# Code linting
npm run lint

# Fix code issues
npm run lint:fix

Adding New Features:

  1. Edit the file src/nodes/WhatsAppDecrypt/WhatsAppDecrypt.node.ts
  2. Add new parameters to the properties array
  3. Modify execution logic in the execute method
  4. Build the project and test changes

šŸ› Troubleshooting

Common Issues:

  1. "MAC verification failed"

    • Verify the mediaKey is correct
    • Try different decryption methods
    • Check media type matches the file
  2. "Failed to download file"

    • Verify the file URL is correct
    • Check internet connection
  3. "Decryption failed"

    • Verify mediaKey correctness
    • Ensure correct message type
  4. "Invalid media type"

    • Use supported types: audioMessage, videoMessage, imageMessage, documentMessage, stickerMessage

šŸ” Debugging

Enable Debug Logging:

The node includes detailed logging for troubleshooting. Check n8n logs for:

[Auto Decrypt] Trying HKDF Library
[HKDF Decrypt] Starting decryption with external HKDF library
[Auto Decrypt] Success with HKDF Library

šŸ¤ Contributing

Contributions are welcome! Please:

  1. Fork the project
  2. Create a branch for the new feature
  3. Implement changes with tests
  4. Submit a Pull Request

šŸ“ License

MIT License

šŸ“ž Support

If you encounter issues or have questions, please:

  1. Open an issue on GitHub
  2. Check the documentation
  3. Review common issues in the troubleshooting section

šŸ”— Links


Important Note: This extension is for educational and development purposes. Make sure to comply with WhatsApp's terms of service and local privacy laws when using it.

Discussion