Skip to content

A Node.js module to simplify using the built-in "crypto" module for AES256 encryption with random initialization vectors.

License

Notifications You must be signed in to change notification settings

JamesMGreene/node-aes256

Repository files navigation

aes256

GitHub Latest Release Build Status Coverage Status Dependency Status Dev Dependency Status

A Node.js module to simplify using the built-in crypto module for AES-256 encryption with random initialization vectors.

This module generates a random initialization vector each time one of the encrypt methods is called.

Furthermore, your symmetric session key (a.k.a. secret, a.k.a. passphrase) can be of any size because it is hashed using SHA-256.

Install

$ npm install aes256

Usage

Example using static methods

var aes256 = require('aes256');

var key = 'my passphrase';
var plaintext = 'my plaintext message';
var buffer = Buffer.from(plaintext);

var encryptedPlainText = aes256.encrypt(key, plaintext);
var decryptedPlainText = aes256.decrypt(key, encryptedPlainText);
// plaintext === decryptedPlainText

var encryptedBuffer = aes256.encrypt(key, buffer);
var decryptedBuffer = aes256.decrypt(key, encryptedBuffer);
// plaintext === decryptedBuffer.toString('utf8)

Example using an AesCipher instance

var aes256 = require('aes256');

var key = 'my passphrase';
var plaintext = 'my plaintext message';
var buffer = Buffer.from(plaintext);

var cipher = aes256.createCipher(key);

var encryptedPlainText = cipher.encrypt(plaintext);
var decryptedPlainText = cipher.decrypt(encryptedPlainText);
// plaintext === decryptedPlainText

var encryptedBuffer = cipher.encrypt(buffer);
var decryptedBuffer = cipher.decrypt(encryptedBuffer);
// plaintext === decryptedBuffer.toString('utf8)

API

Documentation maaaaaybe forthcoming....

For now, looking at the above usage examples, the code, or the unit tests should all give you a pretty good idea without much effort as the API surface area is very small.

License

Copyright (c) 2015-2021, James M. Greene (MIT License)

About

A Node.js module to simplify using the built-in "crypto" module for AES256 encryption with random initialization vectors.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •