README
EasyCrypt
A simple bi-directional salting and encryption system designed for securing authentication tokens.
Basic Example
const { ezEncrypt, ezDecrypt } = require("easycrypt");
let stringToEncrypt = "This is easy.";
let crypted = ezEncrypt(stringToEncrypt);
console.log(`Crypted: ${crypted}`);
console.log(`Decrypted: ${ezDecrypt(crypted)}`); // This is easy.3@af2@F#Sd
Validation Example
const { ezDecrypt } = require("easycrypt");
const encryptedString = database.getEncryptedString(); // get encrypted string
const userInput = api.getUserInput(); // get user supplied string to compare to
const salt = encryptedString.split(':');
const decrypt = ezDecrypt(encryptedString);
return `${userInput}${salt}` === decrypt;
Validation without decrypting
const { ezCompare } = require("easycrypt");
const input = 'Easy';
const crypted = ezEncrypt(input);
return ezCompare(input, crypted);
Installing
npm install easycrypt
API
EasyCrypt
Require exports ezEncrpyt, ezDecrypt and ezCompare.
Settings
Environment Variable
The encryption password is stored on an environment variable called EasyCryptPW.
You must set the environment variable before using EasyCrypt.
From the command line:
EasyCryptPW='3zTvzr3p67VC61jmV54rIYu1545x4TlY' node EasyCrypt.js
Functions
ezEncrypt
Used to salt and encrypt a piece of text.
const { ezEncrypt } = require("easycrypt");
const text = ezEncrypt("Easy");
console.log(text);
// x8PNf3Oq/NC/0+wAEvIaYw==:]RYY9)g6MdD@:daGjLpCvnJJy4s95XpNJ7w==:8LC)7