1.1.5 • Published 5 months ago

n8n-nodes-datacrypto v1.1.5

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

n8n-nodes-datacrypto

This is a custom n8n node that provides encryption and decryption capabilities for your workflows. It allows you to secure sensitive data before storing it in databases or sending it to external services, and decrypt it when needed.

Features

  • Encrypt/Decrypt Objects: Process entire data structures in one operation
  • Deterministic Encryption: Same input with same key always produces identical output
  • Deep Recursive Processing: Handles nested objects and arrays with proper type preservation
  • Field Filtering: Skip specific fields from encryption/decryption
  • Type Preservation: Maintains original data types (numbers, booleans, strings) after decryption
  • Graceful Error Handling: Returns original values when decryption fails
  • Simplified Format: Streamlined encrypted output format without redundant characters
  • Security: Uses AES-256-CBC encryption
  • Credentials Storage: Secret encryption keys stored securely in n8n's credentials manager

Installation

Method 1: Direct Installation

# Create a directory for the custom node
mkdir -p ~/n8n-custom-nodes/data-crypto

# Navigate to the directory
cd ~/n8n-custom-nodes/data-crypto

# Create proper directory structure
mkdir -p nodes credentials

# Copy the provided files to their respective directories:
# - EncryptionDecryption.node.ts to nodes/
# - DataCryptoCredentials.credentials.ts to credentials/
# - index.ts, package.json, and tsconfig.json to root directory

# Install dependencies
npm install

# Build the node
npm run build

# Start n8n with custom nodes
N8N_CUSTOM_EXTENSIONS=~/n8n-custom-nodes n8n

Method 2: For n8n Desktop App

For macOS:

mkdir -p ~/Library/Application\ Support/n8n/custom/data-crypto
cd ~/Library/Application\ Support/n8n/custom/data-crypto
# Copy files and compile as in Method 1

For Windows:

mkdir -p %APPDATA%\n8n\custom\data-crypto
cd %APPDATA%\n8n\custom\data-crypto
# Copy files and compile as in Method 1

Method 3: For Docker

# Create a directory on the host
mkdir -p ~/n8n-custom-nodes/data-crypto
cd ~/n8n-custom-nodes/data-crypto
# Copy files and compile as in Method 1

# Run n8n with the custom directory mounted
docker run -it --rm \
  -v ~/n8n-custom-nodes:/home/node/.n8n/custom \
  -p 5678:5678 \
  n8nio/n8n

File Structure

data-crypto/
├── nodes/
│   └── EncryptionDecryption.node.ts
├── credentials/
│   └── DataCryptoCredentials.credentials.ts
├── index.ts
├── package.json
├── tsconfig.json
└── README.md

Credential Setup

Before using the node, you need to create credentials:

  1. Open n8n and go to Credentials
  2. Click Create and select Data Crypto Credentials
  3. Enter a name for your credentials and your 32-character secret key
  4. Click Save

The secret key must be exactly 32 characters long for AES-256 encryption.

Usage

Node Configuration

  1. Operation: Choose between "Encrypt" or "Decrypt"
  2. Input Data: The data object to process (default: {{ $json }})
  3. Skip Fields: Comma-separated list of field names to skip (optional)
  4. Credentials: Select your saved Data Crypto Credentials with the encryption key

Example Workflows

Example 1: Encrypting User Data Before Storage

  1. Webhook Node → Receive user data
  2. Data Crypto Node:
    • Operation: Encrypt
    • Input Data: {{ $json }}
    • Skip Fields: id,created_at
    • Credentials: Your saved Data Crypto Credentials
  3. NocoDB Node → Store encrypted data

Example 2: Retrieving and Decrypting Data

  1. NocoDB Node → Fetch encrypted data
  2. Data Crypto Node:
    • Operation: Decrypt
    • Input Data: {{ $json }}
    • Credentials: Your saved Data Crypto Credentials (same used for encryption)
  3. Send Email Node → Use decrypted data

Security Notes

  • Store your secret key securely: The credentials system helps with this, but guard your n8n credentials carefully
  • Key length: Must be exactly 32 characters for AES-256 encryption
  • Deterministic encryption: This node uses a fixed initialization vector (IV) to ensure identical outputs for identical inputs, which is useful for database storage but provides less security than random IVs
  • Security trade-offs: Be aware that identical input values will produce identical encrypted outputs, potentially revealing patterns in your data
  • Encrypted format: The new version uses a simplified format that removes redundant characters, making the encrypted output more compact

How It Works

The node uses the Node.js crypto library with AES-256-CBC encryption. Each encryption operation:

  1. Uses a fixed initialization vector (IV) of 16 bytes of zeros
  2. Uses your secret key and the fixed IV to encrypt the data
  3. Returns only the encrypted data without the IV prefix (the IV is fixed)
  4. Processes all nested objects and arrays recursively, preserving structure
  5. Ensures that the same input with the same key always produces the same encrypted output
  6. For decryption, automatically uses the fixed IV without requiring it in the input

Improved Features

  • Deep Recursive Processing: The node now properly handles nested objects and arrays, going as deep as needed to find and encrypt/decrypt primitive values
  • Error Handling: When decryption fails for any reason, the node returns the original value instead of raising an error
  • Simplified Format: The encrypted output no longer includes the redundant "00000000000000000000000000000000:" prefix
  • Structure Preservation: Complex data structures maintain their original format after encryption/decryption

Troubleshooting

ErrorSolution
"Secret key must be exactly 32 characters"Make sure your key is exactly 32 characters long
Decryption returns original valueThe value may not have been encrypted with this node or may be using a different key
TypeScript compilation errorsMake sure your tsconfig.json is correctly set up
Node not appearing in n8nCheck the n8n logs for errors; verify the node file path is correct

License

MIT

Contributing

Feel free to submit issues and enhancement requests.

1.1.5

5 months ago

1.1.4

5 months ago

1.1.3

5 months ago

1.1.0

5 months ago

1.0.1

6 months ago

1.0.0

6 months ago