Aerostack
security

sec-decrypt-aes Edge Function — Security

Security

Decrypts an AES-256-GCM encrypted bundle produced by sec-encrypt-aes — key is derived via SHA-256, auth tag is verified automatically.

navin @navin verified
Updated Mar 12, 2026
GitHub

Edge function sec-decrypt-aes Decrypts an AES-256-GCM encrypted bundle produced by sec-encrypt-aes — key is derived via SHA-256, auth tag is verified automatically.. 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-decrypt-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-decrypt-aes",
  args: {
    "encrypted": "example_encrypted",
    "key": "example_key"
  }
})

sec-decrypt-aes — Decrypt AES-256-GCM encrypted bundles

Decrypts ciphertext produced by sec-encrypt-aes using AES-256-GCM via the Web Crypto API. Throws a clear error if the key is wrong or the data has been tampered with.


API

POST /api/sec-decrypt-aes

Request body

Field Type Required Description
encrypted string The iv:ciphertext bundle from sec-encrypt-aes
key string Same passphrase used during encryption

Success response (200)

{
  "success": true,
  "data": {
    "text": "sensitive data"
  }
}

Error responses

Code HTTP When
INVALID_INPUT 400 Missing encrypted or key
INTERNAL_ERROR 500 Wrong key, tampered data, or invalid bundle format

Usage

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

const { text } = await decryptAes({ encrypted: storedBundle, key: 'my-passphrase' });

Use Cases

  • Recovering PII (emails, phone numbers) stored encrypted in a database
  • Decrypting short-lived tokens or secrets transported in URL parameters
  • Reading encrypted configuration blobs from storage
  • Verifying webhook payloads were not tampered during transport

Notes

  • Throws "Decryption failed: wrong key or tampered data" when the auth tag doesn't match — any bit flip in the ciphertext is detected
  • Throws "Decryption failed: invalid encrypted bundle format" for malformed input
  • Use exactly the same key string used during encryption
  • Pair with sec-encrypt-aes — the bundle format is base64(iv):base64(ciphertext+authTag)

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-decrypt-aes function do? +

sec-decrypt-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-decrypt-aes function? +

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

What runtime does sec-decrypt-aes use? +

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

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

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