des_encrypt
Encrypt text using DES algorithm with customizable key, IV, padding mode, and output format for secure data protection.
Instructions
encrypt text with des
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | text to encrypt | |
| key | No | encryption key, default is your-key | |
| iv | No | initialization vector, default is your-iv- | your-iv- |
| padding | No | padding mode, default is Pkcs7 | Pkcs7 |
| outputFormat | No | output format, default is base64 | base64 |
| mode | No | mode, default is ECB | ECB |
Implementation Reference
- src/service/des.ts:402-454 (handler)Handler function that dispatches DES encryption based on mode (ECB/CBC/CFB/OFB/CTR) using DESUtil helpers, returns encrypted text.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 defining input parameters for des_encrypt: content, optional key/iv/padding/outputFormat/mode with 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)Registers the 'des_encrypt' tool on the MCP server within registerDESTool function.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)Calls registerDESTool to register des_encrypt and des_decrypt tools on the main server.registerDESTool(server);
- src/service/des.ts:25-40 (helper)DESUtil.encryptECB: Core helper for ECB mode encryption using CryptoJS.DES.encrypt.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(); }