des_decrypt
Decrypt text using DES algorithm with configurable modes, padding, and input formats for secure data handling.
Instructions
decrypt text with des
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | text to decrypt | |
| key | No | decryption key, default is your-key | |
| iv | No | initialization vector, default is your-iv- | your-iv- |
| padding | No | padding mode, default is Pkcs7 | Pkcs7 |
| inputFormat | No | input format, default is base64 | base64 |
| mode | No | mode, default is ECB | ECB |
Implementation Reference
- src/service/des.ts:495-540 (handler)The main handler function for the 'des_decrypt' tool. It dispatches to the appropriate DESUtil.decrypt* method based on the 'mode' parameter (ECB, CBC, CFB, OFB, CTR) and returns the decrypted text.async ({ content, key, iv, padding, inputFormat, mode }) => { let result = ""; if (mode === "ECB") { result = DESUtil.decryptECB(content, key ?? "your-key"); } else if (mode === "CBC") { result = DESUtil.decryptCBC( content, key ?? "your-key", iv ?? "your-iv-", (padding ?? "Pkcs7") as PaddingMode, (inputFormat ?? "base64") as OutputFormat ); } else if (mode === "CFB") { result = DESUtil.decryptCFB( content, key ?? "your-key", iv ?? "your-iv-", (padding ?? "Pkcs7") as PaddingMode, (inputFormat ?? "base64") as OutputFormat ); } else if (mode === "OFB") { result = DESUtil.decryptOFB( content, key ?? "your-key", iv ?? "your-iv-", (padding ?? "Pkcs7") as PaddingMode, (inputFormat ?? "base64") as OutputFormat ); } else if (mode === "CTR") { result = DESUtil.decryptCTR( content, key ?? "your-key", iv ?? "your-iv-", (padding ?? "Pkcs7") as PaddingMode, (inputFormat ?? "base64") as OutputFormat ); } return { content: [ { type: "text", text: result, }, ], }; }
- src/service/des.ts:461-494 (schema)Zod schema for input validation of the 'des_decrypt' tool parameters: content (encrypted text), key, iv, padding, inputFormat, and mode.{ content: z.string().describe("text to decrypt"), key: z .string() .optional() .describe("decryption key, default is your-key"), iv: z .string() .optional() .describe("initialization vector, default is your-iv-") .default("your-iv-"), 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"), mode: z .enum(["ECB", "CBC", "CFB", "OFB", "CTR"]) .optional() .describe("mode, default is ECB") .default("ECB"), },
- src/service/des.ts:458-541 (registration)The server.tool registration for the 'des_decrypt' tool, including name, description, schema, and handler.server.tool( "des_decrypt", "decrypt text with des", { content: z.string().describe("text to decrypt"), key: z .string() .optional() .describe("decryption key, default is your-key"), iv: z .string() .optional() .describe("initialization vector, default is your-iv-") .default("your-iv-"), 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"), mode: z .enum(["ECB", "CBC", "CFB", "OFB", "CTR"]) .optional() .describe("mode, default is ECB") .default("ECB"), }, async ({ content, key, iv, padding, inputFormat, mode }) => { let result = ""; if (mode === "ECB") { result = DESUtil.decryptECB(content, key ?? "your-key"); } else if (mode === "CBC") { result = DESUtil.decryptCBC( content, key ?? "your-key", iv ?? "your-iv-", (padding ?? "Pkcs7") as PaddingMode, (inputFormat ?? "base64") as OutputFormat ); } else if (mode === "CFB") { result = DESUtil.decryptCFB( content, key ?? "your-key", iv ?? "your-iv-", (padding ?? "Pkcs7") as PaddingMode, (inputFormat ?? "base64") as OutputFormat ); } else if (mode === "OFB") { result = DESUtil.decryptOFB( content, key ?? "your-key", iv ?? "your-iv-", (padding ?? "Pkcs7") as PaddingMode, (inputFormat ?? "base64") as OutputFormat ); } else if (mode === "CTR") { result = DESUtil.decryptCTR( content, key ?? "your-key", iv ?? "your-iv-", (padding ?? "Pkcs7") as PaddingMode, (inputFormat ?? "base64") as OutputFormat ); } return { content: [ { type: "text", text: result, }, ], }; } );
- src/service/des.ts:50-76 (helper)DESUtil.decryptECB: Helper function for ECB mode decryption, called by the handler when mode='ECB' (default). Uses CryptoJS.DES.decrypt.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.DES.decrypt(ciphertextParams, keyHex, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad[padding], }); } else { decrypted = CryptoJS.DES.decrypt(ciphertext, keyHex, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad[padding], }); } return decrypted.toString(CryptoJS.enc.Utf8); }
- src/index.ts:17-17 (registration)Top-level call to registerDESTool, which registers the 'des_decrypt' tool among others.registerDESTool(server);