Skip to main content
Glama

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
NameRequiredDescriptionDefault
contentYestext to encrypt
ivNoinitialization vector, default is your-iv-your-iv-
keyNoencryption key, default is your-key
modeNomode, default is ECBECB
outputFormatNooutput format, default is base64base64
paddingNopadding mode, default is Pkcs7Pkcs7

Implementation Reference

  • 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, }, ], }; }
  • 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"), },
  • 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);
  • 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(); }

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