UNPKG

@kikiutils/node

Version:

A modular utility library for Node.js offering secure hashing, flexible logging, datetime manipulation, and more.

50 lines (47 loc) 2.01 kB
import { createHash } from 'node:crypto'; /** * This file provides a set of functions for creating hash digests using different algorithms and bit lengths. * It includes functions for generating SHA-3 hash digests with bit lengths of 224, 256, 384, and 512, * as well as a function for generating MD5 hash digests. * These functions use the Node.js crypto module to generate the hashes. * Can only be used in Node.js/Deno/Bun runtimes. * * @example * ```typescript * import { cryptoSha3256 } from '@kikiutils/node/crypto-hash'; * * console.log(cryptoSha3256('test')); // 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80 * ``` */ function cryptoMd5(data, outputEncoding = 'hex') { return createHash('md5').update(data).digest(outputEncoding); } function cryptoMd5ToBuffer(data) { return createHash('md5').update(data).digest(); } function cryptoSha3224(data, outputEncoding = 'hex') { return createHash('sha3-224').update(data).digest(outputEncoding); } function cryptoSha3224ToBuffer(data) { return createHash('sha3-224').update(data).digest(); } function cryptoSha3256(data, outputEncoding = 'hex') { return createHash('sha3-256').update(data).digest(outputEncoding); } function cryptoSha3256ToBuffer(data) { return createHash('sha3-256').update(data).digest(); } function cryptoSha3384(data, outputEncoding = 'hex') { return createHash('sha3-384').update(data).digest(outputEncoding); } function cryptoSha3384ToBuffer(data) { return createHash('sha3-384').update(data).digest(); } function cryptoSha3512(data, outputEncoding = 'hex') { return createHash('sha3-512').update(data).digest(outputEncoding); } function cryptoSha3512ToBuffer(data) { return createHash('sha3-512').update(data).digest(); } export { cryptoMd5, cryptoMd5ToBuffer, cryptoSha3224, cryptoSha3224ToBuffer, cryptoSha3256, cryptoSha3256ToBuffer, cryptoSha3384, cryptoSha3384ToBuffer, cryptoSha3512, cryptoSha3512ToBuffer }; //# sourceMappingURL=crypto-hash.mjs.map