Skip to main content
Glama

aes_decrypt

Decrypt AES-encrypted text using specified keys, modes, and padding formats to restore original data securely.

Instructions

decrypt text with aes

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentYestext to encrypt and decrypt
keyNodecrypt key, default is your-key-0123456
paddingNopadding mode, default is Pkcs7Pkcs7
inputFormatNoinput format, default is base64base64
ivNoiv, default is your-iv-01234567
modeNomode, default is ECBECB

Implementation Reference

  • The handler function that implements the logic for the 'aes_decrypt' tool. It selects the appropriate AES decryption method based on the 'mode' parameter and returns the decrypted text.
    async ({ content, key, padding, inputFormat, iv, mode }) => { let result = ""; if (mode === "ECB") { result = AESUtil.decryptECB(content, key ?? "your-key-0123456"); } else if (mode === "CBC") { result = AESUtil.decryptCBC( content, key ?? "your-key-0123456", iv ?? "your-iv-01234567", (padding ?? "Pkcs7") as PaddingMode, (inputFormat ?? "base64") as OutputFormat ); } else if (mode === "CFB") { result = AESUtil.decryptCFB( content, key ?? "your-key-0123456", iv ?? "your-iv-01234567", (padding ?? "Pkcs7") as PaddingMode, (inputFormat ?? "base64") as OutputFormat ); } else if (mode === "OFB") { result = AESUtil.decryptOFB( content, key ?? "your-key-0123456", iv ?? "your-iv-01234567", (padding ?? "Pkcs7") as PaddingMode, (inputFormat ?? "base64") as OutputFormat ); } else if (mode === "CTR") { result = AESUtil.decryptCTR( content, key ?? "your-key-0123456", iv ?? "your-iv-01234567", (padding ?? "Pkcs7") as PaddingMode, (inputFormat ?? "base64") as OutputFormat ); } return { content: [ { type: "text", text: result, }, ], }; } );
  • Zod schema defining the input parameters for the 'aes_decrypt' tool, including content, key, padding, inputFormat, iv, and mode with descriptions and defaults.
    { content: z.string().describe("text to encrypt and decrypt"), key: z .string() .optional() .describe("decrypt key, default is your-key-0123456"), padding: z .enum([ "Pkcs7", "Iso97971", "AnsiX923", "Iso10126", "ZeroPadding", "NoPadding", ]) .optional() .describe("padding mode, default is Pkcs7") .default("Pkcs7"), inputFormat: z .enum(["base64", "hex"]) .optional() .describe("input format, default is base64") .default("base64"), iv: z.string().optional().describe("iv, default is your-iv-01234567"), mode: z .enum(["ECB", "CBC", "CFB", "OFB", "CTR"]) .optional() .describe("mode, default is ECB") .default("ECB"), },
  • The MCP server.tool registration call for the 'aes_decrypt' tool within the registerAESTool function.
    server.tool( "aes_decrypt", "decrypt text with aes", { content: z.string().describe("text to encrypt and decrypt"), key: z .string() .optional() .describe("decrypt key, default is your-key-0123456"), padding: z .enum([ "Pkcs7", "Iso97971", "AnsiX923", "Iso10126", "ZeroPadding", "NoPadding", ]) .optional() .describe("padding mode, default is Pkcs7") .default("Pkcs7"), inputFormat: z .enum(["base64", "hex"]) .optional() .describe("input format, default is base64") .default("base64"), iv: z.string().optional().describe("iv, default is your-iv-01234567"), mode: z .enum(["ECB", "CBC", "CFB", "OFB", "CTR"]) .optional() .describe("mode, default is ECB") .default("ECB"), }, async ({ content, key, padding, inputFormat, iv, mode }) => { let result = ""; if (mode === "ECB") { result = AESUtil.decryptECB(content, key ?? "your-key-0123456"); } else if (mode === "CBC") { result = AESUtil.decryptCBC( content, key ?? "your-key-0123456", iv ?? "your-iv-01234567", (padding ?? "Pkcs7") as PaddingMode, (inputFormat ?? "base64") as OutputFormat ); } else if (mode === "CFB") { result = AESUtil.decryptCFB( content, key ?? "your-key-0123456", iv ?? "your-iv-01234567", (padding ?? "Pkcs7") as PaddingMode, (inputFormat ?? "base64") as OutputFormat ); } else if (mode === "OFB") { result = AESUtil.decryptOFB( content, key ?? "your-key-0123456", iv ?? "your-iv-01234567", (padding ?? "Pkcs7") as PaddingMode, (inputFormat ?? "base64") as OutputFormat ); } else if (mode === "CTR") { result = AESUtil.decryptCTR( content, key ?? "your-key-0123456", iv ?? "your-iv-01234567", (padding ?? "Pkcs7") as PaddingMode, (inputFormat ?? "base64") as OutputFormat ); } return { content: [ { type: "text", text: result, }, ], }; } );
  • src/index.ts:15-15 (registration)
    Top-level registration of AES tools (including aes_decrypt) by calling registerAESTool on the MCP server.
    registerAESTool(server);
  • Helper function for AES ECB mode decryption, used by the aes_decrypt handler.
    static decryptECB( ciphertext: string, key: string, padding: PaddingMode = "Pkcs7", inputFormat: OutputFormat = "base64" ): string { const keyHex = CryptoJS.enc.Utf8.parse(key); let decrypted; if (inputFormat === "hex") { const ciphertextHex = CryptoJS.enc.Hex.parse(ciphertext); const ciphertextParams = CryptoJS.lib.CipherParams.create({ ciphertext: ciphertextHex, }); decrypted = CryptoJS.AES.decrypt(ciphertextParams, keyHex, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad[padding], }); } else { decrypted = CryptoJS.AES.decrypt(ciphertext, keyHex, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad[padding], }); } return decrypted.toString(CryptoJS.enc.Utf8); }

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