Giter Site home page Giter Site logo

blind's Introduction

blind

simple string encryption and hashing

features

  • for hiding small text strings
  • all functions return Promises (server friendly)
  • helpful error messages
  • Node only, wraps crypto functions
  • web application (coming soon)

constructor

var Blind = require('blind');
var blind = new Blind(options);
// or
var blind = Blind.create(options);

options / properties and defaults

  • binaryEncoding - 'base64' or 'hex', encoding of random values, keys, salt, encrypted values and hashes
  • encryptionAlgorithm - 'aes-256-cfb', algorithm used in encrypt() and decrypt(); see crypto.getCiphers() for a list of valid values
  • hashLength - 60, length in bytes of hashed values (before encoding)
  • hashRounds - 10000, number of hashing iterations
  • maxDataLength - 4096, maximum length in characters of data to be encrypted or hashed
  • maxRandomLength - 120, maximum length in bytes of random values (before encoding)
  • skipChecks - false, skip property and argument checks on function calls; improves performance, returns cryptic error messages when it fails

functions

random(length)

Generates a random value of the specified length in bytes. Returns a Promise which returns the random values as a binary-encoded string. Use this to generate keys and salt for the functions below. Wraps crypto.randomBytes.

Blind.create()
  .random(16)
  .then(function (value) {
    // example: 'PZ3oXv2v6Pq5HAPFI9NFbQ=='
  });

Blind.create({ binaryEncoding: 'hex' })
  .random(16)
  .then(function (value) {
    // example: '5dfc4556a70e95a9cfda08975187b165'
  });

encrypt(data, key)

Encrypts plain text data using the binary-encoded key. Returns a Promise which returns the encrypted value as a binary-encoded string. Wraps crypto.Cipher.

Blind.create()
  .encrypt('Blueberry pancakes', 'PZ3oXv2v6Pq5HAPFI9NFbQ==')
  .then(function (value) {
    assert.equal(value, 'IXH46BLKBXwZcC2QyNHB+EmJ');
  });

Blind.create({ encryptAlgorithm: 'blowfish' })
  .encrypt('Blueberry pancakes', 'PZ3oXv2v6Pq5HAPFI9NFbQ==')
  .then(function (value) {
    assert.equal(value, '1Uv7F3uWgc8g9uW3HlGFdWigBGQq4Hku');
  });

decrypt(encrypted, key)

Decrypts the string of encrypted data using the binary-encoded key. Returns a Promise which returns the plain text value. Wraps crypto.Decipher.

Blind.create()
  .decrypt('IXH46BLKBXwZcC2QyNHB+EmJ', 'PZ3oXv2v6Pq5HAPFI9NFbQ==')
  .then(function (value) {
    assert.equal(value, 'Blueberry pancakes');
  });

Blind.create({ encryptAlgorithm: 'blowfish' })
  .decrypt('1Uv7F3uWgc8g9uW3HlGFdWigBGQq4Hku', 'PZ3oXv2v6Pq5HAPFI9NFbQ==')
  .then(function (value) {
    assert.equal(value, 'Blueberry pancakes');
  });

hash(data, salt)

Hashes plain text data using an optional binary-encoded salt value. Returns a Promise which returns the hashed value as a binary-encoded string. Wraps crypto.pbkdf2.

Blind.create()
  .hash('Banana nut muffin', 'PZ3oXv2v6Pq5HAPFI9NFbQ==');
  .then(function (value) {
    assert.equal(value, 'lxl9UhUNyNYTPG6IJkILWu3ibNZQxTl5m+qE906UFi0WaR6SQoxMBqxop3H9t1HwuDo2Lyl9YNJJ1gUZ');
  });

Blind.create({ hashLength: 30 })
  .hash('Banana nut muffin', 'PZ3oXv2v6Pq5HAPFI9NFbQ==');
  .then(function (value) {
    assert.equal(value, 'lxl9UhUNyNYTPG6IJkILWu3ibNZQxTl5m+qE906U');
  });

blind's People

Contributors

pgirard avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.