des_encrypt
Encrypt text using DES encryption with customizable key, IV, padding, and output format. Supports multiple modes for secure data handling on the Crypto_MCP server.
Instructions
encrypt text with des
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | text to encrypt | |
| iv | No | initialization vector, default is your-iv- | your-iv- |
| key | No | encryption key, default is your-key | |
| mode | No | mode, default is ECB | ECB |
| outputFormat | No | output format, default is base64 | base64 |
| padding | No | padding mode, default is Pkcs7 | Pkcs7 |
Implementation Reference
- src/service/des.ts:402-454 (handler)The main handler function that executes the DES encryption logic. It dispatches to specific mode handlers (ECB, CBC, CFB, OFB, CTR) in DESUtil based on the 'mode' parameter and returns the encrypted result as MCP content.async ({ content, key, iv, padding, outputFormat, mode }) => { let result = ""; if (mode === "ECB") { result = DESUtil.encryptECB( content, key ?? "your-key", (padding ?? "Pkcs7") as PaddingMode, (outputFormat ?? "base64") as OutputFormat ); } else if (mode === "CBC") { result = DESUtil.encryptCBC( content, key ?? "your-key", iv ?? "your-iv-", (padding ?? "Pkcs7") as PaddingMode, (outputFormat ?? "base64") as OutputFormat ); } else if (mode === "CFB") { result = DESUtil.encryptCFB( content, key ?? "your-key", iv ?? "your-iv-", (padding ?? "Pkcs7") as PaddingMode, (outputFormat ?? "base64") as OutputFormat ); } else if (mode === "OFB") { result = DESUtil.encryptOFB( content, key ?? "your-key", iv ?? "your-iv-", (padding ?? "Pkcs7") as PaddingMode, (outputFormat ?? "base64") as OutputFormat ); } else if (mode === "CTR") { result = DESUtil.encryptCTR( content, key ?? "your-key", iv ?? "your-iv-", (padding ?? "Pkcs7") as PaddingMode, (outputFormat ?? "base64") as OutputFormat ); } else { throw new McpError(ErrorCode.InvalidParams, "Unknown mode"); } return { content: [ { type: "text", text: result, }, ], }; }
- src/service/des.ts:368-401 (schema)Zod schema for input validation of the des_encrypt tool, defining parameters like content, key, iv, padding, outputFormat, and mode with descriptions and defaults.{ content: z.string().describe("text to encrypt"), key: z .string() .optional() .describe("encryption 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"), outputFormat: z .enum(["base64", "hex"]) .optional() .describe("output format, default is base64") .default("base64"), mode: z .string() .optional() .describe("mode, default is ECB") .default("ECB"), },
- src/service/des.ts:365-455 (registration)The server.tool() registration of the des_encrypt tool, including name, description, input schema, and handler function within the registerDESTool.server.tool( "des_encrypt", "encrypt text with des", { content: z.string().describe("text to encrypt"), key: z .string() .optional() .describe("encryption 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"), outputFormat: z .enum(["base64", "hex"]) .optional() .describe("output format, default is base64") .default("base64"), mode: z .string() .optional() .describe("mode, default is ECB") .default("ECB"), }, async ({ content, key, iv, padding, outputFormat, mode }) => { let result = ""; if (mode === "ECB") { result = DESUtil.encryptECB( content, key ?? "your-key", (padding ?? "Pkcs7") as PaddingMode, (outputFormat ?? "base64") as OutputFormat ); } else if (mode === "CBC") { result = DESUtil.encryptCBC( content, key ?? "your-key", iv ?? "your-iv-", (padding ?? "Pkcs7") as PaddingMode, (outputFormat ?? "base64") as OutputFormat ); } else if (mode === "CFB") { result = DESUtil.encryptCFB( content, key ?? "your-key", iv ?? "your-iv-", (padding ?? "Pkcs7") as PaddingMode, (outputFormat ?? "base64") as OutputFormat ); } else if (mode === "OFB") { result = DESUtil.encryptOFB( content, key ?? "your-key", iv ?? "your-iv-", (padding ?? "Pkcs7") as PaddingMode, (outputFormat ?? "base64") as OutputFormat ); } else if (mode === "CTR") { result = DESUtil.encryptCTR( content, key ?? "your-key", iv ?? "your-iv-", (padding ?? "Pkcs7") as PaddingMode, (outputFormat ?? "base64") as OutputFormat ); } else { throw new McpError(ErrorCode.InvalidParams, "Unknown mode"); } return { content: [ { type: "text", text: result, }, ], }; } );
- src/index.ts:17-17 (registration)Top-level call to registerDESTool(server) in the main MCP server setup, which registers the des_encrypt tool among others.registerDESTool(server);
- src/service/des.ts:25-40 (helper)DESUtil.encryptECB helper method implementing ECB mode DES encryption using CryptoJS, called by the handler when mode='ECB'.static encryptECB( message: string, key: string, padding: PaddingMode = "Pkcs7", outputFormat: OutputFormat = "base64" ): string { const keyHex = CryptoJS.enc.Utf8.parse(key); const encrypted = CryptoJS.DES.encrypt(message, keyHex, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad[padding], }); return outputFormat === "base64" ? encrypted.toString() : encrypted.ciphertext.toString(); }