An open API service indexing awesome lists of open source software.

https://github.com/mingchen/node-crypto-gcm

A node crypto wrap for AES GCM
https://github.com/mingchen/node-crypto-gcm

aes authentication crypto gcm node

Last synced: 4 months ago
JSON representation

A node crypto wrap for AES GCM

Awesome Lists containing this project

README

          

node-crypto-gcm
===============

[![Build Status](https://travis-ci.org/mingchen/node-crypto-gcm.svg?branch=master)](https://travis-ci.org/mingchen/node-crypto-gcm)
[![Greenkeeper badge](https://badges.greenkeeper.io/mingchen/node-crypto-gcm.svg)](https://greenkeeper.io/)

[![NPM](https://nodei.co/npm/node-crypto-gcm.png?downloads=true)](https://nodei.co/npm/node-crypto-gcm/)

## Introduction

A node crypto wrap for AES [GCM (Galois/Counter Mode)](https://en.wikipedia.org/wiki/Galois/Counter_Mode),
to make it easy to use AES GCM mode.

The default crypto algorithm is `aes-128-gcm`. PBKDF2 digest algorithm is `sha512`, PBKDF2 rounds is 10000.

The output text is URL safe base64 encoding, so it can be safely used in URL without URL encoding.

## Install

npm install node-crypto-gcm

## Usage

const GCM = require('node-crypto-gcm').GCM;

let plainText = 'To be or not to be, that is the question.';
let gcm = new GCM('password');

let output = gcm.encrypt(plainText);

let decryptedText = gcm.decrypt(output); // decryptedText should equals plainText

The crypto algorithm can be customized in constructor.

let gcm = new GCM('t86GvATWQV6S', {algorithm: 'aes-256-gcm',
saltLenght: 123,
pbkdf2Rounds: 1000,
pbkdf2Digest: 'sha512'});

Checkout [test/gcm_test.js](test/gcm_test.js) for example usages.

## API

class GCM {

/**
* @param password {string} password string, will use PBKDF2 to drive encryption key.
* @param options {object} optional algorithm parameters.
* specific this parameter to custom your own encryption algorithm.
* {algorithm: ,
* saltLength:
* pbkdf2Rounds: ,
* pbkdf2Digest:
*/
constructor(password, options)

/**
* Encrypt plainText.
*
* The output raw buffer format:
*
*
*
* it will be url safe base64 encoded as function return value.
*
* @param plainText utf-8 encoded plain text.
* @returns {string} url safe base64 encoded encrypted text.
*/
encrypt(plainText)

/**
* decrypt encyptedData.
*
* @param encryptedData {string} encrypted data, url safe base64 encoded.
* @returns {*} decrypted data, utf-8 encoded. or null if decrypt failed.
*/
decrypt(encryptedData)
}

## License

MIT

## References

* [nodejs crypto API](https://nodejs.org/api/crypto.html)