Skip to main content
Glama

aes_decrypt

Decrypt AES-encrypted text using a specified key, padding, and mode. Supports various input formats and configurations for secure data handling.

Instructions

decrypt text with aes

Input Schema

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

Implementation Reference

  • Handler function that executes the aes_decrypt tool logic. Determines the AES mode and calls the corresponding AESUtil.decrypt method to decrypt the content, then returns the result as text content.
    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 input schema for the aes_decrypt tool, defining parameters like content (ciphertext), 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"), },
  • Direct registration of the aes_decrypt tool within the registerAESTool function using server.tool() with name, description, schema, and handler.
    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)
    Invocation of registerAESTool in the main server setup, which registers the aes_decrypt tool among others.
    registerAESTool(server);
  • AESUtil.decryptECB helper method for ECB mode decryption, used by the handler when mode is ECB (default). Handles base64/hex input using CryptoJS.
    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); }

Other Tools

Related Tools

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