1.0.2 ā€¢ Published 3 years ago

ciphcrypt v1.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

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.
  • 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 šŸ˜Š