On this page
Sommatic Docs
Open portal

Encrypt Data

Encrypts data with AES-256-GCM (random IV, authenticated).

View as Markdown
Open in
Identity Available crypto.encrypt Version 2.0.0 Execution: sync

Encrypts any JSON value with AES-256-GCM and returns a versioned token v1.<iv>.<tag>.<ciphertext> (base64url). The key comes from an encryption-key credential (connection_id) or, discouraged, from a literal key.

How it works

  1. Resolves the config. A pure expression such as {{ $json.payment }} in data keeps the value type; mixed text always yields a string.
  2. Leaves through error with data is required when data is undefined, null or an empty string.
  3. Picks the key: connection_id first, otherwise the literal key. With neither, the node leaves through error.
  4. Wraps the value as { "v": data }, encrypts it with a random 12-byte IV and joins version, IV, authentication tag and ciphertext with dots.
  5. Returns { encrypted, algorithm } on out, with a secret-free audit record in meta.crypto and literal-key warnings in meta.warnings.

In a workflow

The node as it appears in a workflow file (draft_nodes[]), and the envelope of a successful run.

{
  "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 }}"
  }
}

Configuration

connection_id string Optional

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

key string Optional

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 any Required

Data to encrypt (any JSON value)

Behaviour in the code

What the implementation does with these keys beyond what the schema says.

connection_id
Takes precedence over the literal key. The credential is resolved on the server when the node runs, so the secret never appears in the flow. A string secret is used as the key; an object secret must carry key or secret.
key
Used only when connection_id is empty. Accepts 64 hexadecimal characters, base64 of 32 bytes, or any other text as a passphrase. Literal keys work, but they are stored in the flow, its version history and Git, and meta.warnings reports them.
data
Any JSON value. Objects, arrays, numbers and booleans come back with their type from crypto.decrypt.

Output ports

out default

The value was encrypted.

Data
{
  "encrypted": "v1.sEZVicEyZQ3qzFNu.L_Y2ciTg_ZoET8aUKmDTuw.SRzvsE_YNuaJMYT7_OF3xFIwECFqgqkxBnj3iyY",
  "algorithm": "aes-256-gcm"
}
error

data is missing, no key is configured, or the credential cannot be resolved or has no usable key.

Data
{
  "error": "data is required"
}

In expressions

What a later node can read from this node's output with $("Encrypt Data").item.json.<path> (write your node's label instead of Encrypt Data). Editor marks the paths the workflow editor suggests under Previous Nodes (the output contract); Worker marks the paths the worker really returns through out, from the output shown in Ports.

ExpressionEditorWorker
$("Encrypt Data").item.json.encryptedstring= "v1.sEZVicEyZQ3qzFNu.L_Y2ciTg_ZoET8aUKmDTuw.S…"v1.<iv>.<tag>.<ciphertext> (base64url)
$("Encrypt Data").item.json.algorithmstring= "aes-256-gcm"

Errors

Message Port Cause and fix
data is required error data is empty or its expression resolved to nothing. 0 and false are valid values.
A key is required: pass { credential: "<alias>" } (recommended) or { key } error Neither connection_id nor the literal key field is set. Select a credential in connection_id.
credential binding 'connection' has no key usable for symmetric error The credential resolved, but its secret is empty or is an object without a usable field. Store the key as a string, or as an object with the field this operation reads (see connection_id).
Failed to resolve connection <connection_id>: <detail> error The credential id does not exist or is not available to this workflow. Check the id and the credential type.

Input contract

connection_id string Optional
key string Optional
data any Required

Output contract

encrypted string Optional

v1.<iv>.<tag>.<ciphertext> (base64url)

algorithm string Optional

Contracts (JSON Schema)

The definition exactly as the orchestrator declares it. All is the whole *.definition.js; compare it with the sections above to spot differences between the documentation and the schema. Use it to validate a node before you publish.

{
  "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
    }
  }
}

Execution

Execution
sync
Stateful
No
Capabilities
cryptoencryption
Tags
cryptosecurity

Notes and limits

  • Every run uses a fresh random IV, so the same value encrypted twice gives different tokens. Do not compare tokens for equality; use crypto.hash for that.
  • Only crypto.decrypt with the same key reads the token (format v1).
  • Leaving through error does not fail the run: the engine follows the edges wired to error, and if there are none the branch simply ends.

Reviewed against the orchestrator code · 31e874b · 2026-11-26

Install agent tools

Give your coding agent the official Sommatic AI docs: skills, the docs MCP server and Markdown pages, so it never has to scrape the site.

Skills only. They do not update by themselves; run it again to refresh.

npx skills add https://docs.sommatic.ai
How agents read these docs