AutomationFlowsGeneral › Xor Encryption and Decryption with Base64 Encoding for Workflow Data

Xor Encryption and Decryption with Base64 Encoding for Workflow Data

ByTenkay @tenkay on n8n.io

This workflow performs basic XOR-based encryption and decryption using a custom password. It is intended to be triggered by another workflow and processes structured input in JSON format.

Event trigger★★★★☆ complexity4 nodesExecute Workflow Trigger
General Trigger: Event Nodes: 4 Complexity: ★★★★☆ Added:

This workflow corresponds to n8n.io template #5025 — we link there as the canonical source.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "id": "fElANcOcJejintLK",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "simple-encryption",
  "tags": [],
  "nodes": [
    {
      "id": "61c0e04b-bbac-4c1f-8dee-d2e8096cecc9",
      "name": "When Executed by Another Workflow",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        -140,
        20
      ],
      "parameters": {
        "workflowInputs": {
          "values": [
            {
              "name": "action-type"
            },
            {
              "name": "key"
            },
            {
              "name": "data"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "29fec805-be45-40bf-a7a5-52dcdc6a4e9e",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        80,
        20
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "8f844b57-5893-44f8-a1c8-de653bfbac9e",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json['action-type'] }}",
              "rightValue": "encrypt"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "9c293a9b-7d52-4d97-a0b5-578e9f228b89",
      "name": "encrypt",
      "type": "n8n-nodes-base.code",
      "position": [
        300,
        -80
      ],
      "parameters": {
        "jsCode": "const message =$input.first().json.data || \"No Data\";\nconst key = $input.first().json.key;\n\nfunction xorEncrypt(text, key) {\n  let encrypted = \"\";\n  for (let i = 0; i < text.length; i++) {\n    const charCode = text.charCodeAt(i) ^ key.charCodeAt(i % key.length);\n    encrypted += String.fromCharCode(charCode);\n  }\n  return Buffer.from(encrypted).toString('base64'); \n}\n\nreturn [\n  {\n    json: {\n      encrypted: xorEncrypt(message, key)\n    }\n  }\n];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "9376e4af-0923-404d-a596-8090cc0f9c8f",
      "name": "decrypt",
      "type": "n8n-nodes-base.code",
      "position": [
        300,
        120
      ],
      "parameters": {
        "jsCode": "const encrypted = $input.first().json.data;\nconst key = $input.first().json.key; // Must be the same key used to encrypt\n\nfunction xorDecrypt(base64Text, key) {\n  const text = Buffer.from(base64Text, 'base64').toString();\n  let decrypted = \"\";\n  for (let i = 0; i < text.length; i++) {\n    const charCode = text.charCodeAt(i) ^ key.charCodeAt(i % key.length);\n    decrypted += String.fromCharCode(charCode);\n  }\n  return decrypted;\n}\n\nreturn [\n  {\n    json: {\n      decrypted: xorDecrypt(encrypted, key)\n    }\n  }\n];\n"
      },
      "typeVersion": 2
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "83f71006-74d3-4e44-a8f7-47c5312dabf1",
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "encrypt",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "decrypt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When Executed by Another Workflow": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

This workflow performs basic XOR-based encryption and decryption using a custom password. It is intended to be triggered by another workflow and processes structured input in JSON format.

Source: https://n8n.io/workflows/5025/ — original creator credit. Request a take-down →

More General workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

General

Agendamiento. Uses n8n-nodes-evolution-api, redis, dataTable, executeWorkflowTrigger. Event-driven trigger; 60 nodes.

N8N Nodes Evolution Api, Redis, Data Table +2
General

Prevent concurrent workflow runs using Redis. Uses executeWorkflowTrigger, manualTrigger, stickyNote, executeWorkflow. Event-driven trigger; 43 nodes.

Execute Workflow Trigger, Redis, Stop And Error
General

This workflow sets a small "lock" value in Redis so that only one copy of a long job can run at the same time. If another trigger fires while the job is still busy, the workflow sees the lock, stops e

Execute Workflow Trigger, Redis, Stop And Error
General

Reputation Engine — Site Refresh. Uses httpRequest, executeWorkflowTrigger. Event-driven trigger; 35 nodes.

HTTP Request, Execute Workflow Trigger
General

Using n8n a lot?

Execute Workflow Trigger, XML, Move Binary Data +1