aes_encrypt
Encrypt text using AES encryption with customizable modes, padding, and output formats for secure data protection.
Instructions
encrypt text with aes
Input Schema
TableJSON 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:402-455 (handler)Handler function for aes_encrypt tool that selects the appropriate AES encryption mode (ECB, CBC, CFB, OFB, CTR) and calls the corresponding AESUtil method to encrypt the content.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:369-401 (schema)Zod schema defining input parameters for the aes_encrypt tool: content, optional key, padding, outputFormat, iv, and mode.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:366-455 (registration)Registers the aes_encrypt tool on the MCP server within the registerAESTool function."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:25-40 (helper)AESUtil.encryptECB: Core helper function for ECB mode encryption, used by default in aes_encrypt handler.static encryptECB( message: string, key: string, padding: PaddingMode = "Pkcs7", outputFormat: OutputFormat = "base64" ): string { const keyHex = CryptoJS.enc.Utf8.parse(key); const encrypted = CryptoJS.AES.encrypt(message, keyHex, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad[padding], }); return outputFormat === "base64" ? encrypted.toString() : encrypted.ciphertext.toString(); }
- src/index.ts:15-15 (registration)Top-level call to registerAESTool in the main server setup, which includes registration of aes_encrypt.registerAESTool(server);