Skip to content

Library for encrypt and decrypt messages using a secret key.

Notifications You must be signed in to change notification settings

cavillo/encryptor-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Encryptor

Build Status

Library for encrypt and decrypt messages using a secret key.

Installation

npm install --save encryptor-node

Import methods

// As a whole
import * as Encryptor from 'encryptor-node';

// Each method
import { encrypt, decrypt } from 'encryptor-node';

Encrypting and decrypting a message or object

import { encrypt, decrypt } from 'encryptor-node';

const secret = 's3cr3t!';
const payload = { message: 'This is an very important message' };

// Encrypting
const encrypted = encrypt(secret, payload);
console.log(encrypted); // e20f64009fe0daa88......

// Decrypting
const result = decrypt(secret, encrypted);
console.log(result); // { message: 'This is an very important message' }

Extra Options

The encrypt function takes an additional optional options hash consisting of the following:

{
  /**
   * Optional - define the algorithm used for encryption
   * @default aes-256-cbc
   */
  algorithm?: string;

  /**
   * Optional - pass your own salt
   */
  salt?: string;

  /**
   * Optional - specify how long the generated salt string should be
   */
  saltLength?: number;

  /**
   * Optional - return encrypted data as a hex string, rather than a buffer. Defaults to true.
   */
  stringify?: boolean;
}

This is provided to allow the developer somewhat more control over the internals of the library. The decrypt function takes an options hash with just the algorithm key.

The algorithm must be compatible with the built-in node crypto library.

About

Library for encrypt and decrypt messages using a secret key.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published