Skip to content

Latest commit

 

History

History
32 lines (24 loc) · 1.31 KB

README.md

File metadata and controls

32 lines (24 loc) · 1.31 KB

version NPM Version size size zipped Supports Treeshaking

Encryption Utility


simple encryption class for node or browser (as of v1.0.0) apps, allows setting app secret & set purpose of encryption, inspired from adonis encryption feature

Quick Start

// Create Static Encryption constant
// src/lib/Encryption.ts
import { default as AppEncryption } from 'encryption.js';
const Encryption = new AppEncryption({ secret: process.env.APP_SECRET })
export default Encryption;

// usage
// src/app.ts or any other ts to use

import Encryption from './lib/Encryption';

// encrypt payload with a expiry date & purpose which acts like a salt, decrypting will require the purpose to return the encrypted object, otherwise null
const token = Encryption.encrypt({ userId: "<some id>" }, Date.now() + 1000 * 60 * 60, "emailVerify");

// some user <> server things

// server handles payload
const payload = Encryption.decrypt(token, "emailVerify");