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

iocane

v5.2.0

Published

Textual encryption library

Downloads

9,887

Readme

iocane

A powerful and easy-to-use text and data encryption library for NodeJS and the web.

Buttercup Downloads per month on NPM npm version

About

iocane makes text and data encryption and decryption easy by bundling all the complicated processes into one succinct library. Encrypt and decrypt strings and buffers easily by using iocane's encryption format - string->string / buffer->buffer. Encrypt and decrypt streams in NodeJS.

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:
    • Text
    • Buffers
    • Streams (only in NodeJS)
  • 256bit keys
  • PBKDF2 key derivation (with 250k/custom iterations)
  • 35KB minified web version (10KB gzipped)
  • Overridable encryption/derivation/packing functionality to allow for adaptation to yet-unsupported environments

Installation

Install iocane as a dependency using npm:

npm install iocane --save

Usage

iocane can be easily used to encrypt text:

import { createAdapter } from "iocane";

createAdapter()
    .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:

import { createAdapter } from "iocane";

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

During encryption, you can override a variety of options:

import { EncryptionAlgorithm, createAdapter } from "iocane";

const encrypted = await createAdapter()
    .setAlgorithm(EncryptionAlgorithm.GCM) // use GCM encryption
    .setDerivationRounds(300000)
    .encrypt(target, password);

Each cryptographic function can be overridden by simply replacing it on the adapter

import { createAdapter } from "iocane";

const adapter = createAdapter();
adapter.deriveKey = async (password: string, salt: string) => { /* ... */ };

await adapter.encrypt(/* ... */);

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

Encrypting and decrypting data buffers

Iocane can handle buffers the same way it handles strings - just pass them into the same encrypt/decrypt functions:

import { createAdapter } from "iocane";
import fs from "fs";

createAdapter()
    .setAlgorithm(EncryptionAlgorithm.CBC)
    .encrypt(fs.readFileSync("./test.bin"), "passw0rd")
    .then(data => fs.writeFileSync("./test.bin.enc", data));

The same can be performed on the web, with array buffers in place of standard buffers.

Encrypting and decrypting using streams

Available on the Node version only.

Iocane can create encryption and decryption streams, which is very useful for encrypting large amounts of data:

import { createAdapter } from "iocane";
import fs from "fs";
import zlib from "zlib";

// Encrypt
fs
    .createReadStream("/my-file.dat")
    .pipe(zlib.createGzip())
    .pipe(createAdapter().createEncryptStream("passw0rd"))
    .pipe(fs.createWriteStream("/destination.dat.enc"));

// Decrypt
fs
    .createReadStream("/destination.dat.enc")
    .pipe(createAdapter().createDecryptStream("passw0rd"))
    .pipe(zlib.createGunzip())
    .pipe(fs.createWriteStream("/my-file-restored.dat"));

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.createAdapter).

Supported environments

iocane supports NodeJS version 10 and above. Node 8 was supported in 3.x and versions prior to 8 were supported in 1.x.

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 were 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.