Aerostack
security

sec-encrypt-aes Edge Function — Security

Security

Encrypts a string with AES-256-GCM using Web Crypto — key is derived via SHA-256, output is a portable IV:ciphertext bundle.

navin @navin verified
Updated Mar 12, 2026
GitHub

Edge function sec-encrypt-aes Encrypts a string with AES-256-GCM using Web Crypto — key is derived via SHA-256, output is a portable IV:ciphertext bundle.. Deployed on Cloudflare Workers — zero cold starts, globally distributed. Mount it via your Aerostack workspace to call it from any AI agent.

terminal — aerostack cli
$ npx aerostack add navin/sec-encrypt-aes
smart_toy

Use with AI Assistants

MCP

Connect Claude, Cursor, or any MCP-compatible client — then call this function by slug

① Add MCP Server

Add this once — access all Aerostack functions from your AI tool.

claude_desktop_config.json
{
  "mcpServers": {
    "aerostack": {
      "url": "https://mcp.aerostack.dev",
      "type": "http"
    }
  }
}

② Call this function

Ask your AI to use the call_function tool with this slug:

call_function
call_function({
  slug: "sec-encrypt-aes",
  args: {
    "text": "example_text",
    "key": "example_key"
  }
})

sec-encrypt-aes — Encrypt strings with AES-256-GCM

Encrypts any string with AES-256-GCM via the Web Crypto API. Key can be any length — it's SHA-256 hashed internally to produce a 256-bit key.


API

POST /api/sec-encrypt-aes

Request body

Field Type Required Description
text string Plaintext to encrypt
key string Encryption passphrase (any length)

Success response (200)

{
  "success": true,
  "data": {
    "encrypted": "dGVzdGl2MTI=:dGVzdGNpcGhlcnRleHQ="
  }
}

Error responses

Code HTTP When
INVALID_INPUT 400 Missing text or key
INTERNAL_ERROR 500 Unexpected error

Usage

cURL
curl -X POST "$FUNCTION_URL" \
  -H "Content-Type: application/json" \
  -d '{"text": "sensitive data", "key": "my-passphrase"}'
TypeScript / JavaScript (HTTP)
const response = await fetch(FUNCTION_URL, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ text: 'sensitive data', key: 'my-passphrase' }),
});
const { data } = await response.json();
console.log(data.encrypted); // store this, pass to sec-decrypt-aes to recover
Direct import (Node / Bun / Deno)
import { encryptAes } from '@aerostack/functions/sec-encrypt-aes';

const { encrypted } = await encryptAes({ text: 'sensitive data', key: 'my-passphrase' });

Use Cases

  • Encrypting PII (emails, phone numbers) before storing in a database
  • Wrapping short-lived tokens or secrets for secure transport in URL parameters
  • Storing encrypted user preferences or configuration blobs
  • Encrypting webhook payloads for secure delivery

Notes

  • Uses AES-256-GCM — provides both confidentiality and authenticity (AEAD)
  • A random 12-byte IV is generated for every encryption — same plaintext always produces different ciphertext
  • The output bundle format is base64(iv):base64(ciphertext+authTag) — self-contained, no state needed
  • Pair with sec-decrypt-aes to reverse — use the same key string
  • Auth tag is embedded in the ciphertext — tampering is detected on decryption

Metadata

upgrade Version 1.0.0
gavel License MIT
language Language typescript
cloud Provider aerostack

Tags

security
deployed_code

Build and publish your own functions

Write a TypeScript function, deploy it to the edge, and share it with thousands of developers — in minutes.

More Security Functions

Browse Security Functions →

Frequently asked questions

What does the sec-encrypt-aes function do? +

sec-encrypt-aes is a serverless edge function for security automation written in aerostack. Deploy it to Cloudflare Workers via your Aerostack workspace.

How do I deploy the sec-encrypt-aes function? +

Install the Aerostack CLI and run: ```bash aerostack deploy function @navin/sec-encrypt-aes ``` It will be live on Cloudflare Workers in seconds.

What runtime does sec-encrypt-aes use? +

sec-encrypt-aes runs on aerostack on the Cloudflare Workers edge runtime — zero cold starts, globally distributed.

Can I customise the sec-encrypt-aes function? +

Yes. Fork the function from your Aerostack dashboard, modify the source, and redeploy. All changes are version-controlled.