UNPKG

@kikiutils/node

Version:

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

61 lines (57 loc) 2.4 kB
'use strict'; const node_crypto = require('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 node_crypto.createHash('md5').update(data).digest(outputEncoding); } function cryptoMd5ToBuffer(data) { return node_crypto.createHash('md5').update(data).digest(); } function cryptoSha3224(data, outputEncoding = 'hex') { return node_crypto.createHash('sha3-224').update(data).digest(outputEncoding); } function cryptoSha3224ToBuffer(data) { return node_crypto.createHash('sha3-224').update(data).digest(); } function cryptoSha3256(data, outputEncoding = 'hex') { return node_crypto.createHash('sha3-256').update(data).digest(outputEncoding); } function cryptoSha3256ToBuffer(data) { return node_crypto.createHash('sha3-256').update(data).digest(); } function cryptoSha3384(data, outputEncoding = 'hex') { return node_crypto.createHash('sha3-384').update(data).digest(outputEncoding); } function cryptoSha3384ToBuffer(data) { return node_crypto.createHash('sha3-384').update(data).digest(); } function cryptoSha3512(data, outputEncoding = 'hex') { return node_crypto.createHash('sha3-512').update(data).digest(outputEncoding); } function cryptoSha3512ToBuffer(data) { return node_crypto.createHash('sha3-512').update(data).digest(); } exports.cryptoMd5 = cryptoMd5; exports.cryptoMd5ToBuffer = cryptoMd5ToBuffer; exports.cryptoSha3224 = cryptoSha3224; exports.cryptoSha3224ToBuffer = cryptoSha3224ToBuffer; exports.cryptoSha3256 = cryptoSha3256; exports.cryptoSha3256ToBuffer = cryptoSha3256ToBuffer; exports.cryptoSha3384 = cryptoSha3384; exports.cryptoSha3384ToBuffer = cryptoSha3384ToBuffer; exports.cryptoSha3512 = cryptoSha3512; exports.cryptoSha3512ToBuffer = cryptoSha3512ToBuffer; //# sourceMappingURL=crypto-hash.cjs.map