Skip to main content
Glama

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
NameRequiredDescriptionDefault
contentYestext to encrypt and decrypt
keyNoencrypt key, default is your-key-0123456
paddingNopadding mode, default is Pkcs7Pkcs7
outputFormatNooutput format, default is base64base64
ivNoiv, default is your-iv-01234567your-iv-01234567
modeNomode, default is ECBECB

Implementation Reference

  • 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, }, ], }; } );
  • 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"), },
  • 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, }, ], }; } );
  • 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);

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/1595901624/crypto-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server