Encrypt Data
使用 AES 加密数据。
使用 AES-256-GCM 加密任意 JSON 值,返回带版本的令牌 v1.<iv>.<tag>.<ciphertext>(base64url)。密钥来自 encryption-key 凭据(connection_id),也可使用字面量 key(不推荐)。
工作原理
- 解析配置。在
data中使用纯表达式(如{{ $json.payment }})可保留值的类型;混合文本始终得到字符串。 - 当
data为 undefined、null 或空字符串时,以data is required从error输出。 - 选择密钥:优先
connection_id,否则使用字面量key。两者都没有时从error输出。 - 将值包装为
{ "v": data },使用随机 12 字节 IV 加密,并用点号连接版本、IV、认证标签和密文。 - 从
out返回{ encrypted, algorithm },meta.crypto中为不含密钥的审计记录,meta.warnings中为字面量密钥警告。
在工作流中
节点在工作流文件(draft_nodes[])中的写法,以及一次成功运行的 envelope。
{
"node_id": "node-encrypt-payment",
"label": "Encrypt payment details",
"operator_slug": "crypto.encrypt",
"operator_version": "2.0.0",
"config": {
"connection_id": "pi-credential-xxxx",
"data": "{{ $json.payment }}"
}
}{
"ok": true,
"port": "out",
"data": {
"encrypted": "v1.sEZVicEyZQ3qzFNu.L_Y2ciTg_ZoET8aUKmDTuw.SRzvsE_YNuaJMYT7_OF3xFIwECFqgqkxBnj3iyY",
"algorithm": "aes-256-gcm"
},
"meta": {
"crypto": {
"op": "encrypt",
"key_source": "credential",
"alias": "connection",
"credential_id": "pi-credential-xxxx",
"algorithm": "aes-256-gcm",
"ok": true
},
"warnings": []
}
}配置
-
connection_idstring 可选 -
Sommatic AI credential resolved server-side (recommended). Accepts credentials of type `encryption-key`.
-
keystring 可选 -
32 个字符的密钥
-
dataany 必填 -
要加密的数据
代码中的行为
除 schema 描述之外,实现代码对这些键的实际处理。
-
connection_id - 优先于字面量
key。凭据在节点运行时于服务端解析,密钥不会出现在流程中。字符串密钥直接作为密钥使用;对象密钥必须包含key或secret。 -
key - 仅在
connection_id为空时使用。接受 64 位十六进制字符、32 字节的 base64,其他文本则作为口令使用。字面量密钥可以使用,但会保存在流程、版本历史和 Git 中,并在meta.warnings中报告。 -
data - 任意 JSON 值。对象、数组、数字和布尔值经
crypto.decrypt解密后保持原类型。
输出端口
out 默认 值已加密。
数据
{
"encrypted": "v1.sEZVicEyZQ3qzFNu.L_Y2ciTg_ZoET8aUKmDTuw.SRzvsE_YNuaJMYT7_OF3xFIwECFqgqkxBnj3iyY",
"algorithm": "aes-256-gcm"
}error 缺少 data、未配置密钥,或凭据无法解析或没有可用密钥。
数据
{
"error": "data is required"
}在表达式中
后续节点可通过 $("Encrypt Data").item.json.<路径> 读取此节点输出中的内容(请把 Encrypt Data 换成你的节点标签)。Editor 标记工作流编辑器在 Previous Nodes 中提示的路径(输出契约);Worker 标记 worker 实际通过 out 返回的路径,依据“端口”一节所示的输出。
| 表达式 | Editor | Worker |
|---|---|---|
$("Encrypt Data").item.json.encryptedHex 编码 | ||
$("Encrypt Data").item.json.algorithm |
错误
| 消息 | 端口 | 原因与处理 |
|---|---|---|
data is required | error | data 为空,或其表达式未解析出任何值。0 和 false 是合法值。 |
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_idstring 可选 -
keystring 可选 -
dataany 必填
输出契约
-
encryptedstring 可选 -
Hex 编码
-
algorithmstring 可选
契约(JSON Schema)
与编排器声明完全一致的定义。All 是完整的 *.definition.js;可与上方各节对照,找出文档与 schema 之间的差异。发布前可用它校验节点。
{
"slug": "crypto.encrypt",
"name": "Encrypt Data",
"category": "identity",
"version": "2.0.0",
"description": "Encrypts data with AES-256-GCM (random IV, authenticated). Output: v1.<iv>.<tag>.<ciphertext>.",
"capabilities": [
"crypto",
"encryption"
],
"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 (64 hex chars, base64 of 32 bytes, or a passphrase) as a literal. Allowed, but it is stored in the flow, its version history and Git: prefer connection_id."
},
"data": {
"description": "Data to encrypt (any JSON value)"
}
},
"required": [
"data"
]
},
"input_contract_schema": {
"type": "object",
"properties": {
"connection_id": {
"type": "string"
},
"key": {
"type": "string"
},
"data": {}
},
"required": [
"data"
]
},
"output_contract_schema": {
"type": "object",
"properties": {
"encrypted": {
"type": "string",
"description": "v1.<iv>.<tag>.<ciphertext> (base64url)"
},
"algorithm": {
"type": "string"
}
}
},
"ports": [
{
"port_id": "out",
"label": "Encrypted",
"description": "Encrypted data",
"is_default": true,
"supports_condition": true
},
{
"port_id": "error",
"label": "Error",
"description": "Encryption 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
}
}
}{
"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 (64 hex chars, base64 of 32 bytes, or a passphrase) as a literal. Allowed, but it is stored in the flow, its version history and Git: prefer connection_id."
},
"data": {
"description": "Data to encrypt (any JSON value)"
}
},
"required": [
"data"
]
}{
"type": "object",
"properties": {
"connection_id": {
"type": "string"
},
"key": {
"type": "string"
},
"data": {}
},
"required": [
"data"
]
}{
"type": "object",
"properties": {
"encrypted": {
"type": "string",
"description": "v1.<iv>.<tag>.<ciphertext> (base64url)"
},
"algorithm": {
"type": "string"
}
}
}[
{
"port_id": "out",
"label": "Encrypted",
"description": "Encrypted data",
"is_default": true,
"supports_condition": true
},
{
"port_id": "error",
"label": "Error",
"description": "Encryption failed",
"is_default": false,
"supports_condition": false
}
]执行
- 执行方式
sync- 有状态
- 否
- 能力
cryptoencryption- 标签
cryptosecurity
说明与限制
- 每次运行都使用新的随机 IV,同一个值加密两次会得到不同的令牌。不要比较令牌是否相等,请改用
crypto.hash。 - 只有使用相同密钥的
crypto.decrypt才能读取该令牌(v1格式)。 - 从
error端口输出不会使运行失败:引擎沿error上的连线继续;若没有连线,该分支直接结束。
已对照编排器代码核实 · 31e874b · 2026-11-26