Skip to content

Encrypt/Decrypt tokens send from server/client, only decryptable from server. supports objects

Notifications You must be signed in to change notification settings

Venipa/encryption.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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");

About

Encrypt/Decrypt tokens send from server/client, only decryptable from server. supports objects

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published