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

Hash Data

使用 SHA/MD5 对数据进行哈希。

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

计算值的十六进制 SHA-256、SHA-384 或 SHA-512 摘要。字符串按 UTF-8 计算;其他值先序列化为 JSON。

工作原理

  1. 解析配置;在 data 中使用纯表达式,例如 {{ $json.email }}。
  2. 当 data 为 undefined、null 或空字符串时,以 data is required 从 error 输出。
  3. 校验 algorithm(默认 sha256)是否为 sha256、sha384 或 sha512。
  4. 非字符串值用 JSON.stringify 序列化,再对 UTF-8 文本计算摘要。
  5. 从 out 返回 { hash }(小写十六进制),并附带 meta.crypto。

在工作流中

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

{
  "node_id": "node-hash-email",
  "label": "Hash customer email",
  "operator_slug": "crypto.hash",
  "operator_version": "2.0.0",
  "config": {
    "data": "{{ $json.email }}",
    "algorithm": "sha256"
  }
}

配置

data any 必填

Data to hash (objects are JSON-serialized)

algorithm string 可选

默认值: sha256

可选值: sha256sha384sha512

代码中的行为

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

data
对象通过 JSON.stringify 序列化,键的顺序会影响结果:{"a":1,"b":2} 与 {"b":2,"a":1} 的摘要不同。跨系统比较摘要时,请先规范化该值。

输出端口

out 默认

摘要已计算。

数据
{
  "hash": "8c87b489ce35cf2e2f39f80e282cb2e804932a56a213983eeeb428407d43b52d"
}
error

缺少 data,或算法不受支持。

数据
{
  "error": "Unsupported hash algorithm: md5"
}

在表达式中

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

表达式EditorWorker
$("Hash Data").item.json.hashstring= "8c87b489ce35cf2e2f39f80e282cb2e804932a56a213…"Hex 编码

错误

消息 端口 原因与处理
data is required error data 为空,或其表达式未解析出任何值。0 和 false 是合法值。
Unsupported hash algorithm: <algorithm> error 仅支持 sha256、sha384 和 sha512。

输入契约

data any 必填
algorithm string 可选

输出契约

hash string 可选

Hex 编码

契约(JSON Schema)

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

{
  "slug": "crypto.hash",
  "name": "Hash Data",
  "category": "identity",
  "version": "2.0.0",
  "description": "Hashes data with SHA-256, SHA-384 or SHA-512 (hex).",
  "capabilities": [
    "crypto",
    "hash"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "data": {
        "description": "Data to hash (objects are JSON-serialized)"
      },
      "algorithm": {
        "type": "string",
        "default": "sha256",
        "enum": [
          "sha256",
          "sha384",
          "sha512"
        ]
      }
    },
    "required": [
      "data"
    ]
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "data": {},
      "algorithm": {
        "type": "string"
      }
    },
    "required": [
      "data"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "hash": {
        "type": "string"
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Hash",
      "description": "Hashed string",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Hash 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
有状态
否
能力
cryptohash
标签
cryptosecurity

说明与限制

  • 该摘要不带密钥:相同输入始终得到相同结果,适合做相等性比较和假名化键。
  • 从 error 端口输出不会使运行失败:引擎沿 error 上的连线继续;若没有连线,该分支直接结束。

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

安装智能体工具

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

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

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