hashData
Generate secure hashes from input data using specified algorithms like MD5, SHA1, SHA256, or SHA512, with output in hex or base64 encoding. Ideal for data integrity and security applications.
Instructions
Hash input data using Node.js crypto module
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| algorithm | No | Hash algorithm to use | sha256 |
| encoding | No | Output encoding | hex |
| input | Yes | Data to hash |
Implementation Reference
- src/tools/security.ts:30-58 (handler)The asynchronous handler function that executes the hashing logic using Node.js crypto.createHash, taking input data, algorithm, and encoding parameters.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)The inputSchema defining the parameters for the hashData tool: input (required string), algorithm (enum with default sha256), encoding (enum with default hex).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:27-33 (registration)Registration of securityTools (including hashData) by spreading into the allTools object used by MCP server handlers for tool listing and execution.const allTools: ToolKit = { ...encodingTools, ...geoTools, ...generatorTools, ...dateTimeTools, ...securityTools };
- src/types.ts:53-53 (schema)Type definition for HashAlgorithm used in the hashData input schema and handler.export type HashAlgorithm = 'md5' | 'sha1' | 'sha256' | 'sha512';