hashData
Generate cryptographic hashes for data using algorithms like SHA256 or MD5 to verify integrity or create digital fingerprints.
Instructions
Hash input data using Node.js crypto module
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| input | Yes | Data to hash | |
| algorithm | No | Hash algorithm to use | sha256 |
| encoding | No | Output encoding | hex |
Implementation Reference
- src/tools/security.ts:30-58 (handler)The core handler function for the 'hashData' tool. It hashes the provided input string using the specified algorithm (default: sha256) and encoding (default: hex) via Node.js 'crypto.createHash', then returns a structured JSON response containing the inputs and computed hash.handler: async ({ input, algorithm = 'sha256', encoding = 'hex' }: { input: string; algorithm?: HashAlgorithm; encoding?: 'hex' | 'base64' }) => { try { const hash = createHash(algorithm) .update(input) .digest(encoding); return { content: [{ type: 'text', text: JSON.stringify({ input, algorithm, encoding, hash }, null, 2) }] }; } catch (error) { throw new Error(`Hashing failed: ${error instanceof Error ? error.message : 'Unknown error'}`); } }
- src/tools/security.ts:8-29 (schema)Input schema for the 'hashData' tool, defining required 'input' string, optional 'algorithm' enum (md5/sha1/sha256/sha512), and optional 'encoding' enum (hex/base64).inputSchema: { type: 'object', properties: { input: { type: 'string', description: 'Data to hash' }, algorithm: { type: 'string', description: 'Hash algorithm to use', enum: ['md5', 'sha1', 'sha256', 'sha512'], default: 'sha256' }, encoding: { type: 'string', description: 'Output encoding', enum: ['hex', 'base64'], default: 'hex' } }, required: ['input'] },
- src/index.ts:10-10 (registration)Import statement that brings in the securityTools object, which defines and exports the 'hashData' tool.import { securityTools } from './tools/security.js';
- src/index.ts:28-35 (registration)Merges 'securityTools' (containing 'hashData') into the central 'allTools' registry, making it available for MCP server tool listing and execution handlers.const allTools: ToolKit = { ...systemTools, ...networkTools, ...geoTools, ...generatorTools, ...dateTimeTools, ...securityTools };