npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ciphcrypt

v1.0.2

Published

minimun collection of functions to simplify the use of node's "crypto" module

Downloads

6

Readme

CiphCryptJS

Minimum set of functions for easy encrypt/decrypt text from node's 'crypto' module.

This set of functions should be consider a kind of shorcuts for crypto with default values preset.

NOTICE ⚠️

Encrypt function calls twice or more with the same password don't generate the same hash, this is by the use of a new random salt/iv* wich is generated each time the function is called.

Salt used to encrypt is append to the string returned; thus the finall returned string has the follow structure: encrypted:salt

*Initialization Vector

ADVICE 💡

  • DON'T HARDCODED YOUR SECRET KEYS; insted, prefer use 'dot files'; dotenv is an excelent tool for simplify that task.

  • DON'T MAKE YOUR OWN ALGORITHM; avoid security risk using confidence algorithms and invest some time reading about it. The examples provided by crypto module are good entry point.

Gettig started 🚀

Installation:

npm install -S ciphcrypt

Use

const ciphcrypt = require('ciphcrypt');

const {
  Crypt,
  CryptSync,
  CompareCrypt,
  CompareCryptSync,
  CiphGenerator,
  Cipher,
  Decipher
} = ciphcrypt;

Requirements 📋

  • Node 12

Tests ⚙️

Pending...

Examples 😎

One way encrypt with "Promises" (async)

const {
  Crypt,
  CompareCrypt,
} = require('ciphcrypt');

const password = 'password in plain text';

Crypt(password)
  .then(result => {

    const hashedPassword = result;
    console.log(result);
    // prints a string like this: 692059...63f6:b600a945...471

    const incoming = 'wrong incoming password'

    CompareCrypt(incoming, hashedPassword)
      .then(result => {
        console.log(result);
        // prints "false"
      });

    CompareCrypt(password, hashedPassword)
      .then(result => {
        console.log(result);
        // prints "true"
      });
  });

One way encrypt with sync functions ⚠️

const {
  CryptSync,
  CompareCryptSync,
} = require('ciphcrypt');

const password = 'password in plain text';

const hashedPassword = CryptSync(password);
console.log(hashedPassword);
// prints a string like this: 692059...63f6:b600a945...471

const wrongPassword = 'wrong password'

console.log(CompareCryptSync(wrongPassword, hashedPassword));
// prints "false"
console.log(CompareCryptSync(password, hashedPassword));
// prints "true"

⚠️ Sync function are provided for certain edge use cases; prefer to use async versions to take advantage of the javascript's nature 😉

Two ways encrypt

const {
  Cipher,
  Decipher,
} = require('ciphcrypt');

const yourSuperSecretKey = process.env.YOUR_SECRET_KEY || 'your  32  characters  length key';

const text = 'your text to cipher';

let cipherText = Cipher(text, yourSuperSecretKey);

console.log(cipherText);
// prints a string like this: 692059...63f6:b600a945...471

let decipherText = Decipher(cipherText, yourSuperSecretKey);

console.log(decipherText);
// prints 'your text to cipher'

Two ways encrypt using wrapper generator*

const {
  CiphGenerator
} = require('ciphcrypt');

const yourSuperSecretKey = process.env.YOUR_SECRET_KEY || 'some  32  characters  length key';

const {Decipher, Cipher} = new CiphGenerator(yourSuperSecretKey, 'aes-256-cbc');

const text = 'your text to cipher';

let cipherText = Cipher(text);

console.log(cipherText);
// prints a string like this: 692059...63f6:b600a945...471

let decipherText = Decipher(cipherText);

console.log(decipherText);
// prints 'your text to cipher'

*Using wrapper function you could configure once and export ready to use functions; this way you avoid reference your "secretkey" on various places.

Documentation 📄

Checkout the examples 😅

TODOS 📝

Current:

  • [ ] Add documentation.
  • [ ] Add automated test.
  • [x] Add types definitions. (Thanks Geopic)
  • [ ] Add more algorithms/modes*

*Currently support: 'aes-256-crt', 'aes-256-cbc', 'aes-256-ofb', 'aes-256-cfb' & 'aes-256-ocb'

Next:

  • [ ] Add generation function to allow customize more settings.

Contributing 🖇️

Please read CONTRIBUTING.md.

Version 📌

This project use SemVer.

Authors ✒️

Licence 📄

This project is under licence MIT - see file LICENSE.md for details.


Made with ❤️ by lensanag 😊