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
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | text to encrypt and decrypt | |
| inputFormat | No | input format, default is base64 | base64 |
| iv | No | iv, default is your-iv-01234567 | |
| key | No | decrypt key, default is your-key-0123456 | |
| mode | No | mode, default is ECB | ECB |
| padding | No | padding mode, default is Pkcs7 | Pkcs7 |
Implementation Reference
- src/service/aes.ts:491-537 (handler)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, }, ], }; } );
- src/service/aes.ts:461-490 (schema)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"), },
- src/service/aes.ts:458-537 (registration)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);
- src/service/aes.ts:50-76 (helper)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); }