@utilify/crypto
v1.0.0
Published
These functions are useful for ensuring data security and integrity in web and back-end applications.
Downloads
77
Maintainers
Readme
Utilities - Crypto
The Crypto category provides functions that help with generating cryptographic hashes and creating unique identifiers. These functions are useful for ensuring data security and integrity in web and back-end applications.
Installation
To install the Crypto package, use one of the following commands:
npm install @utilify/crypto
yarn add @utilify/crypto
pnpm add @utilify/crypto
Import the functions into your project:
import { djb2, hash, randomUUID } from '@utilify/crypto';
const { djb2, hash, randomUUID } = require('@utilify/crypto');
Overview
djb2
function djb2(str: string): string;
Calculates the DJB2 hash of a string. The DJB2 algorithm is a fast and efficient way to generate a hash from a text input.
hash
async function hash(
data: string | ArrayBuffer | DataView,
algorithm: 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512',
output: 'hex' | 'base64' | 'buffer' = 'buffer'
): Promise<string | ArrayBuffer | undefined>;
Generates a cryptographic hash of the given data using the specified algorithm and output format.
randomUUID
function randomUUID(): string | undefined;
Generates a secure UUID using the browser's Web Crypto API. Returns undefined
if the API is unavailable.