8
n8n 中文网amn8n.com

简单加密

初级

这是一个Building Blocks领域的自动化工作流,包含 4 个节点。主要使用 If, Code, ExecuteWorkflowTrigger 等节点。 使用 Base64 编码对工作流数据进行 XOR 加密和解密

前置要求
  • 无特殊前置要求,导入即可使用

使用的节点 (4)

工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "fElANcOcJejintLK",
  "meta": {
    "instanceId": "b502e5a8bc6c091b48560caa78bb54b47e56d5b7f2538880db0015950174c8b7",
    "templateCredsSetupCompleted": true
  },
  "name": "简单加密",
  "tags": [],
  "nodes": [
    {
      "id": "61c0e04b-bbac-4c1f-8dee-d2e8096cecc9",
      "name": "当由另一个工作流执行时",
      "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": "如果",
      "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": "加密",
      "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": "解密",
      "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,
  "pinData": {},
  "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
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

初级 - 构建模块

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
初级
节点数量4
分类1
节点类型3
难度说明

适合 n8n 新手,包含 1-5 个节点的简单工作流

作者
Tenkay

Tenkay

@tenkay

I'm a software developer with over 11 years of experience building systems across various stacks. I'm now applying that expertise to create practical and scalable workflow automations with n8n — focusing on clean logic, real-world use cases, and reusability. Always open to learning, sharing, and collaborating.

外部链接
在 n8n.io 查看

分享此工作流