本页内容
Sommatic 文档
打开控制台

Decrypt Data

使用 AES 解密数据。

以 Markdown 查看
在以下应用中打开
身份 可用 crypto.decrypt 版本 2.0.0 执行方式: sync

解密由 crypto.encrypt 生成的 v1.<iv>.<tag>.<ciphertext> 令牌,并在 data 中返回原始 JSON 值。

工作原理

  1. 解析配置;encrypted 通常为 {{ $json.encrypted }}。
  2. 当 encrypted 为空时,以 encrypted data is required 从 error 输出。
  3. 选择密钥:优先 connection_id,否则使用字面量 key。
  4. 检查格式:由点号分隔的四段,第一段为 v1。
  5. 使用 AES-256-GCM 解密并校验认证标签:密钥错误或令牌被篡改都会失败。
  6. 从 out 返回 { data: <原始值> },审计记录位于 meta.crypto。

在工作流中

节点在工作流文件(draft_nodes[])中的写法,以及一次成功运行的 envelope。

{
  "node_id": "node-decrypt-payment",
  "label": "Decrypt payment details",
  "operator_slug": "crypto.decrypt",
  "operator_version": "2.0.0",
  "config": {
    "connection_id": "pi-credential-xxxx",
    "encrypted": "{{ $json.encrypted }}"
  }
}

配置

connection_id string 可选

Sommatic AI credential resolved server-side (recommended). Accepts credentials of type `encryption-key`.

key string 可选

Encryption key as a literal. Allowed, but it is stored in the flow, its version history and Git: prefer connection_id.

encrypted string 必填

v1.<iv>.<tag>.<ciphertext>

代码中的行为

除 schema 描述之外,实现代码对这些键的实际处理。

connection_id
优先于字面量 key。凭据在节点运行时于服务端解析,密钥不会出现在流程中。字符串密钥直接作为密钥使用;对象密钥必须包含 key 或 secret。必须与 crypto.encrypt 使用的密钥相同。
key
字面量密钥可以使用,但会保存在流程、版本历史和 Git 中,并且每次运行都会在 meta.warnings 中报告。建议使用 connection_id。

输出端口

out 默认

令牌已解密并通过认证。

数据
{
  "data": {
    "card_last4": "4242",
    "amount": 129.9,
    "currency": "USD"
  }
}
error

令牌缺失或格式错误、密钥错误,或凭据无法解析。

数据
{
  "error": "Decryption failed: wrong key or tampered value"
}

在表达式中

后续节点可通过 $("Decrypt Data").item.json.<路径> 读取此节点输出中的内容(请把 Decrypt Data 换成你的节点标签)。Editor 标记工作流编辑器在 Previous Nodes 中提示的路径(输出契约);Worker 标记 worker 实际通过 out 返回的路径,依据“端口”一节所示的输出。

表达式EditorWorker
$("Decrypt Data").item.json.dataany= {…}Decrypted value
$("Decrypt Data").item.json.data.card_last4string编辑器不提示= "4242"—
$("Decrypt Data").item.json.data.amountnumber编辑器不提示= 129.9—
$("Decrypt Data").item.json.data.currencystring编辑器不提示= "USD"—

— Worker: worker 会返回它,但编辑器不会提示:请手动输入。对象内部的键可能取决于你的数据或配置(例如每个标签一个键)。

错误

消息 端口 原因与处理
encrypted data is required error encrypted 为空。
Invalid encrypted value: expected v1.<iv>.<tag>.<ciphertext> error 该值不是 crypto.encrypt 生成的令牌(例如传入了整个 { encrypted, algorithm } 对象,而不是 encrypted)。
Decryption failed: wrong key or tampered value error 密钥与加密时使用的不同,或令牌被修改或截断。
A key is required: pass { credential: "<alias>" } (recommended) or { key } error connection_id 和字面量密钥字段都未设置。请在 connection_id 中选择一个凭据。
credential binding 'connection' has no key usable for symmetric error 凭据已解析,但其密钥为空,或是缺少可用字段的对象。请将密钥存为字符串,或存为包含本操作所读字段的对象(见 connection_id)。
Failed to resolve connection <connection_id>: <detail> error 凭据 id 不存在,或该工作流无权使用。请检查 id 和凭据类型。

输入契约

connection_id string 可选
key string 可选
encrypted string 必填

输出契约

data any 可选

Decrypted value

契约(JSON Schema)

与编排器声明完全一致的定义。All 是完整的 *.definition.js;可与上方各节对照,找出文档与 schema 之间的差异。发布前可用它校验节点。

{
  "slug": "crypto.decrypt",
  "name": "Decrypt Data",
  "category": "identity",
  "version": "2.0.0",
  "description": "Decrypts a value produced by crypto.encrypt or $encrypt. Fails if the key is wrong or the value was altered.",
  "capabilities": [
    "crypto",
    "decryption"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "connection_id": {
        "type": "string",
        "title": "Encryption key credential",
        "description": "Sommatic AI credential resolved server-side (recommended). Accepts credentials of type `encryption-key`.",
        "ui_widget": "connection_picker",
        "ui_options": {
          "credential_types": [
            "encryption-key"
          ]
        }
      },
      "key": {
        "type": "string",
        "ui_widget": "password",
        "x-literal-secret": true,
        "description": "Encryption key as a literal. Allowed, but it is stored in the flow, its version history and Git: prefer connection_id."
      },
      "encrypted": {
        "type": "string",
        "description": "v1.<iv>.<tag>.<ciphertext>"
      }
    },
    "required": [
      "encrypted"
    ]
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "connection_id": {
        "type": "string"
      },
      "key": {
        "type": "string"
      },
      "encrypted": {
        "type": "string"
      }
    },
    "required": [
      "encrypted"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "data": {
        "description": "Decrypted value"
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Decrypted",
      "description": "Decrypted string",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Decryption failed",
      "is_default": false,
      "supports_condition": false
    }
  ],
  "execution_mode": "sync",
  "required_resources": [],
  "compatible_worker_pools": [
    "standard"
  ],
  "tags": [
    "crypto",
    "security"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_veripass",
    "profile": {
      "name": "Veripass",
      "verified": true,
      "url": "https://me.veripass.com/veripass",
      "logo_url": null
    }
  }
}

执行

执行方式
sync
有状态
否
能力
cryptodecryption
标签
cryptosecurity

说明与限制

  • 解密值位于 data.data:在下游用 {{ $json.data.amount }} 读取。
  • 从这里开始,解密后的值在运行中是明文数据:避免把它发送到不需要的日志或外部系统。
  • 从 error 端口输出不会使运行失败:引擎沿 error 上的连线继续;若没有连线,该分支直接结束。

已对照编排器代码核实 · 31e874b · 2026-11-26

安装智能体工具

为你的编程智能体接入 Sommatic AI 官方文档:技能包、文档 MCP 服务器与 Markdown 页面,无需再抓取网页。

仅安装技能包,不会自动更新;需要时重新运行即可。

npx skills add https://docs.sommatic.ai
智能体如何读取本文档