node-gpg
GPG encryption and decryption in Node.js
Tech Stack
JavaScriptNode.jsGPG
Features
- Encrypt and decrypt data using GPG
- Stream support for file input/output
- Direct string encryption/decryption
- Full access to GPG command-line options
About node-gpg
Node-GPG is a wrapper around the gpg binary for use within Node.js. It takes care of spawning gpg, passing the correct arguments, and piping input to stdin. It can also handle file streaming for both input and output.
Why Use node-gpg?
Existing JavaScript implementations of PGP are blocking and slow for server use. In testing, encrypting a simple 400-character message took 11-14 seconds with pure JS implementations, but less than 0.1 seconds with gpg directly.
Requirements
The gpg binary must be in your $PATH.
Installation
1npm install gpgUsage
1const gpg = require('gpg');2
3// Encrypt a string4gpg.encrypt('Hello World', ['-r', '[email protected]'], (err, encrypted) => {5 console.log(encrypted);6});7
8// Decrypt data9gpg.decrypt(encryptedBuffer, (err, decrypted) => {10 console.log(decrypted.toString());11});12
13// Stream from/to files14gpg.callStreaming('input.txt', 'output.gpg', ['--encrypt'], callback);Contributors
- Nicholas Penree (drudge)
- freewil
- Samuel Reed (strml)
