no-brainer-crypto
Easy no-brainer encryption and hashing for common use cases with built-in best practices.
Usage
Install package:
# npm
npm install no-brainer-crypto
# yarn
yarn add no-brainer-crypto
# pnpm
pnpm install no-brainer-crypto
Import:
// ESM
import {AesService, Pbkdf2Service, ShaService} from "no-brainer-crypto";
// CommonJS
const {AesService, Pbkdf2Service, ShaService} = require("no-brainer-crypto");
const plainText = "text";
const cipherKey = crypto.randomBytes(32);
ßconst password = "password123";
const aes = new AesService(cipherKey, "aes-256-cbc");
const cipherText = aes.encrypt(plainText);
cipherText === aes.decrypt(cipherText) // true
const pbkdf2 = new Pbkdf2Service();
const passwordHash = pbkdf2.hash(password);
pbkdf2.match({plain: password, hash: passwordHash}); // true
const sha = new ShaService("sha256");
const hash = sha.hash(plainText);
sha.match({plain: plainText, hash}); // true
Development
- Clone this repository
- Install latest LTS version of Node.js
- Install dependencies using
pnpm install
- Run interactive tests using
pnpm dev
License
Made with 💛
Published under MIT License.