Skip to main content
Glama

des_decrypt

Decrypt text using DES encryption with customizable key, IV, padding, and mode. Supports base64 and hex input formats for secure data handling on Crypto_MCP.

Instructions

decrypt text with des

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentYestext to decrypt
inputFormatNoinput format, default is base64base64
ivNoinitialization vector, default is your-iv-your-iv-
keyNodecryption key, default is your-key
modeNomode, default is ECBECB
paddingNopadding mode, default is Pkcs7Pkcs7

Implementation Reference

  • The handler function that implements the core logic for the des_decrypt tool. It selects the appropriate DES decryption method based on the 'mode' parameter (ECB, CBC, CFB, OFB, CTR) and uses DESUtil helpers, then returns the decrypted text in MCP content format.
    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, }, ], }; } );
  • Zod schema defining the input parameters for the des_decrypt tool: encrypted content, key, IV, padding mode, input format, and encryption 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"), },
  • The server.tool() call that registers the des_decrypt tool on the MCP server within the registerDESTool function, specifying name, description, input 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, }, ], }; } );
  • DESUtil.decryptECB: Helper method for ECB mode decryption, used by the des_decrypt handler (default mode). Handles both base64 and hex input formats 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.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)
    Main server setup calls registerDESTool(server), which in turn registers the des_decrypt tool.
    registerDESTool(server);

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