aes_encrypt
Encrypt text using AES algorithm with customizable cipher mode, padding scheme, key, initialization vector, and output format (base64 or hex) for flexible data security.
Instructions
encrypt text with aes
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | text to encrypt and decrypt | |
| key | No | encrypt key, default is your-key-0123456 | |
| padding | No | padding mode, default is Pkcs7 | Pkcs7 |
| outputFormat | No | output format, default is base64 | base64 |
| iv | No | iv, default is your-iv-01234567 | your-iv-01234567 |
| mode | No | mode, default is ECB | ECB |
Implementation Reference
- src/service/aes.ts:363-456 (registration)Registration of the 'aes_encrypt' MCP tool. Calls server.tool('aes_encrypt', ...) with the schema definition and handler.
export function registerAESTool(server: McpServer) { // AES Encrypt server.tool( "aes_encrypt", "encrypt text with aes", { content: z.string().describe("text to encrypt and decrypt"), key: z .string() .optional() .describe("encrypt key, default is your-key-0123456"), padding: z .enum([ "Pkcs7", "Iso97971", "AnsiX923", "Iso10126", "ZeroPadding", "NoPadding", ]) .optional() .describe("padding mode, default is Pkcs7") .default("Pkcs7"), outputFormat: z .enum(["base64", "hex"]) .optional() .describe("output format, default is base64") .default("base64"), iv: z .string() .optional() .describe("iv, default is your-iv-01234567") .default("your-iv-01234567"), mode: z .string() .optional() .describe("mode, default is ECB") .default("ECB"), }, async ({ content, key, padding, outputFormat, iv, mode }) => { let result = ""; if (mode === "ECB") { result = AESUtil.encryptECB( content, key ?? "your-key-0123456", (padding ?? "Pkcs7") as PaddingMode, (outputFormat ?? "base64") as OutputFormat ); } else if (mode === "CBC") { result = AESUtil.encryptCBC( content, key ?? "your-key-0123456", iv ?? "your-iv-01234567", (padding ?? "Pkcs7") as PaddingMode, (outputFormat ?? "base64") as OutputFormat ); } else if (mode === "CFB") { result = AESUtil.encryptCFB( content, key ?? "your-key-0123456", iv ?? "your-iv-01234567", (padding ?? "Pkcs7") as PaddingMode, (outputFormat ?? "base64") as OutputFormat ); } else if (mode === "OFB") { result = AESUtil.encryptOFB( content, key ?? "your-key-0123456", iv ?? "your-iv-01234567", (padding ?? "Pkcs7") as PaddingMode, (outputFormat ?? "base64") as OutputFormat ); } else if (mode === "CTR") { result = AESUtil.encryptCTR( content, key ?? "your-key-0123456", iv ?? "your-iv-01234567", (padding ?? "Pkcs7") as PaddingMode, (outputFormat ?? "base64") as OutputFormat ); } else { throw new McpError(ErrorCode.InvalidParams, "Unknown mode"); } return { content: [ { type: "text", text: result, }, ], }; } ); - src/service/aes.ts:368-401 (schema)Input schema for aes_encrypt tool, defining content, key, padding, outputFormat, iv, and mode parameters using Zod.
{ content: z.string().describe("text to encrypt and decrypt"), key: z .string() .optional() .describe("encrypt key, default is your-key-0123456"), padding: z .enum([ "Pkcs7", "Iso97971", "AnsiX923", "Iso10126", "ZeroPadding", "NoPadding", ]) .optional() .describe("padding mode, default is Pkcs7") .default("Pkcs7"), outputFormat: z .enum(["base64", "hex"]) .optional() .describe("output format, default is base64") .default("base64"), iv: z .string() .optional() .describe("iv, default is your-iv-01234567") .default("your-iv-01234567"), mode: z .string() .optional() .describe("mode, default is ECB") .default("ECB"), }, - src/service/aes.ts:402-454 (handler)Handler function for aes_encrypt. Dispatches to the appropriate AESUtil encryption method based on the mode parameter (ECB, CBC, CFB, OFB, CTR).
async ({ content, key, padding, outputFormat, iv, mode }) => { let result = ""; if (mode === "ECB") { result = AESUtil.encryptECB( content, key ?? "your-key-0123456", (padding ?? "Pkcs7") as PaddingMode, (outputFormat ?? "base64") as OutputFormat ); } else if (mode === "CBC") { result = AESUtil.encryptCBC( content, key ?? "your-key-0123456", iv ?? "your-iv-01234567", (padding ?? "Pkcs7") as PaddingMode, (outputFormat ?? "base64") as OutputFormat ); } else if (mode === "CFB") { result = AESUtil.encryptCFB( content, key ?? "your-key-0123456", iv ?? "your-iv-01234567", (padding ?? "Pkcs7") as PaddingMode, (outputFormat ?? "base64") as OutputFormat ); } else if (mode === "OFB") { result = AESUtil.encryptOFB( content, key ?? "your-key-0123456", iv ?? "your-iv-01234567", (padding ?? "Pkcs7") as PaddingMode, (outputFormat ?? "base64") as OutputFormat ); } else if (mode === "CTR") { result = AESUtil.encryptCTR( content, key ?? "your-key-0123456", iv ?? "your-iv-01234567", (padding ?? "Pkcs7") as PaddingMode, (outputFormat ?? "base64") as OutputFormat ); } else { throw new McpError(ErrorCode.InvalidParams, "Unknown mode"); } return { content: [ { type: "text", text: result, }, ], }; } - src/service/aes.ts:404-410 (handler)ECB encryption branch handler - calls AESUtil.encryptECB with default key if not provided.
if (mode === "ECB") { result = AESUtil.encryptECB( content, key ?? "your-key-0123456", (padding ?? "Pkcs7") as PaddingMode, (outputFormat ?? "base64") as OutputFormat ); - src/index.ts:3-3 (registration)Import of registerAESTool from the aes module, called in the main entry point to register all AES tools including aes_encrypt.
import { registerAESTool } from "./service/aes.js";