Skip to content
This repository has been archived by the owner on Dec 6, 2022. It is now read-only.
/ crypto Public archive

common hash and compare passwords utilities

License

Notifications You must be signed in to change notification settings

ASafaeirad/crypto

Repository files navigation

crypto

Useful encryption and jwt utils

Bcrypt

import { hash, hashSync, compare } from '@frontendmonster/crypto';

const passwordHash = await hash(password, saltLen); // hash password with specific salt and returns Promise<string>
const passwordHashSync = await hashSync(password, saltLen); // hash password with specific salt and returns hash
const isValid = await compare(userPassword, hashedPassword); // compare hashed passwords

Id

import { randomId, randomHex, randomNumber } from '@frontendmonster/crypto';

const id = randomId(16); // create 16-len uid
const hex = randomHex(16); // create 16-len uid
const HEX = randomHex(16, { casing: 'uppercase' }); // create 16-len uppercase hex string
const numbers = randomNumber(16); // create 16-len number string

JWT

import { decode, sign, verify } from '@frontendmonster/crypto';
const jwt = sign(payload, secret, option); // sign json web token
const isValid = verify(jwt, token); // verify json web token
const payload = decode(jwt); // decode json web token