encryptor-node
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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.

Readme

Keywords

Package Sidebar

Install

npm i encryptor-node

Weekly Downloads

69

Version

1.0.0

License

MIT

Unpacked Size

20.7 kB

Total Files

15

Last publish

Collaborators

  • cavillo