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
- Host: GitHub
- URL: https://github.com/mingchen/node-crypto-gcm
- Owner: mingchen
- License: mit
- Created: 2017-03-04T06:36:02.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2022-12-30T17:13:04.000Z (over 3 years ago)
- Last Synced: 2025-10-28T21:42:40.104Z (8 months ago)
- Topics: aes, authentication, crypto, gcm, node
- Language: JavaScript
- Size: 262 KB
- Stars: 9
- Watchers: 2
- Forks: 2
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
node-crypto-gcm
===============
[](https://travis-ci.org/mingchen/node-crypto-gcm)
[](https://greenkeeper.io/)
[](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)