backus / iocane

An odorless, tasteless NodeJS crypto library that dissolves instantly in liquid

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

iocane

NodeJS textual encryption library

Buttercup Build Status Downloads per month on NPM npm version

About

iocane makes text encryption and decryption easy by bundling all the complicated processes into one succinct library. Encrypt and decrypt strings easily by using iocane's encryption format - strings in, strings out.

This library uses "sessions" for encryption and decryption. A session describes one encryption/decryption action, and can also have options be further overridden at the time of execution. Check the examples below for a better idea of how this process works.

iocane works in the browser, too. Both a node version and a web version are available:

const iocane = require("iocane"); // node
import * as iocane from "iocane/web" // web

Features

iocane by default boasts the following features:

  • AES-CBC / AES-GCM encryption
  • 256bit keys
  • PBKDF2 key derivation (with 250k iterations)
  • ~11kb minified web version

Installation

Install iocane as a dependency using npm:

npm install iocane --save

Usage

iocane can be easily used to encrypt text:

const { createSession } = require("iocane");

createSession()
    .encrypt("some secret text", "myPassword")
    .then(encryptedString => {
        // do something with the encrypted text
    });

Decryption is even simpler, as instructions on how to decrypt the payload is included in the payload itself:

createSession()
    .decrypt(encryptedString, "myPassword")
    .then(decryptedString => {
        // ...
    });

During encryption, you can override a variety of options:

createSession()
    .use("gcm") // use GCM encryption
    .setDerivationRounds(300000)
    .encrypt(target, password);

Each cryptographic function can be overridden:

createSession()
    .overrideDecryption("cbc", cbcDecFn)
    .overrideDecryption("gcm", gcmDecFn)
    .overrideEncryption("cbc", cbcEncFn)
    .overrideEncryption("gcm", gcmEncFn)
    .overrideIVGeneration(genIV)
    .overrideKeyDerivation(deriveKey)
    .overrideSaltGeneration(genSalt)
    .encrypt(/* ... */);

Note that the default encryption mode is "cbc" (AES-CBC encryption).

You can check out the API documentation for more information.

Web usage

When building a project for the web, make sure to use the web-based version of iocane. Bundling the node version will create super-large bundles and result in slow encryption and decryption. iocane for the web uses UMD so it can be imported or simply loaded straight in the browser as a <script>.

If you load iocane directly in the browser, it will create a global namespace at window.iocane (eg. window.iocane.createSession).

Supported environments

iocane supports NodeJS version 8 and above. Versions prior to 8 were supported in 1.x but are not anymore.

iocane is used in the browser as well - it works everywhere that SubtleCrypto, ArrayBuffer and Promise are available.

Note: iocane is written in TypeScript, though versions before v2 where written in JavaScript.

Buttercup

iocane was originally part of the Buttercup suite. Buttercup is a supported dependent of iocane and efforts are made to align iocane with Buttercup's target platforms and uses.

About

An odorless, tasteless NodeJS crypto library that dissolves instantly in liquid

License:MIT License


Languages

Language:TypeScript 58.1%Language:JavaScript 41.7%Language:HTML 0.2%