Enhanced simultaneous compression + encryption with NodeJS
npm install libeaes> Enhanced simultaneous compression + encryption
[![NPM Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]
[![NPM][npm-image-url]][npm-url]
Via [NPM][npm]:
`` bash`
npm install libeaes
This installs a CLI binary accessible with the libeaes command.
` bash`Check if libeaes command has been installed and accessible on your path
$ libeaes -v
v1.2.0
The libeaes command, using the algorithm, can perfectly process anything thrown at it. No matter the size. And give useful statistics at the end.
` bash
$ libeaes encrypt file.txt outputfile.enc
$ libeaes decrypt outputfile.enc outputfile.dec
Use
--help to see full usage documentation.
Use --help on specific commands to see docmentation for that command.` bash
$ libeaes encrypt --help
$ libeaes decrypt --help
`The commands can also be shortened to
enc and dec respectfully.` bash
$ libeaes enc file.txt output.enc
$ libeaes dec output.enc output.dec
`$3
` javascript
// Node CommonJS
const libeaes = require('libeaes');
// Or ES6
import libeaes from 'libeaes';
`Examples
$3
` javascript
let password = "#P@$$W0R9";
let encrypted = libeaes.encrypt('Hello world', password);
// Compressed, encrypted contentlet decrypted = libeaes.decrypt(encrypted, password);
// "Hello world"
`$3
` javascript
// Encrypt a stream, pipe output elsewhere
let encryptor = libeaes.EAESEncryptor("#P@$$W0R9");
inputStream.pipe(encryptor).pipe(outputStream);// Decrypt a stream, pipe output elsewhere
let decryptor = libeaes.EAESDecryptor("#P@$$W0R9");
inputStream.pipe(decryptor).pipe(outputStream);
// Stream sequential encryption and decryption operations
let encryptor = libeaes.EAESEncryptor("#P@$$W0R9");
let decryptor = libeaes.EAESDecryptor("#P@$$W0R9");
inputStream.pipe(encryptor).pipe(decryptor).pipe(outputStream);
// inputStream == outputStream
`$3
` javascript
libeaes.encryptFileStream("rawfile.txt", "encryptedfile.txt", "#P@$$W0R9");
libeaes.decryptFileStream("encryptedfile.txt", "decryptedfile.txt", "#P@$$W0R9");
`
API
$3
*
data: [<string>][string] | [<Buffer>][buffer]
* key: [<string>][string] | [<Buffer>][buffer]
* Returns: [<Buffer>][buffer]Compress + Encrypt the input data, return the processed data
$3
*
data: [<string>][string] | [<Buffer>][buffer]
* key: [<string>][string] | [<Buffer>][buffer]
* Returns: [<Buffer>][buffer]Decrypt + Decompress the input data, return the processed data
$3
*
data: [<string>][string] | [<Buffer>][buffer]
* key: [<string>][string] | [<Buffer>][buffer]
* Returns: [<Buffer>][buffer]Encrypt the input data, return the processed data.
Input data is encrypted without initial compression.
$3
*
data: [<string>][string] | [<Buffer>][buffer]
* key: [<string>][string] | [<Buffer>][buffer]
* Returns: [<Buffer>][buffer]Decrypt raw input data, return the processed data.
Input data is assumed to be uncompressed.
$3
*
key: [<string>][string] | [<Buffer>][buffer]
* opts: <zlib options>Create a Transforming EAES Encryptor.
Data piped in here is compressed and encryped with the
key configuration.EAES Streams are encrypted, compressed streams that are tailored to the algorithm in this repo.
The
opts object are passed directly into [zlib.Gzip][gzip]#### Event:
'error'*
err: [<Error>][error]
* code: [<number>][number]This is emitted by either the compression or encryption process.
code is 1 when emitted by the encryption engine and [undefined][undefined] otherwise.Catch errors explicitly with the
'error:compressor' and 'error:encryptor' events.#### Event:
'error:encryptor'*
err: [<Error>][error]The
'error:encryptor' event is emitted if an error occurred while encrypting compressed data. The listener callback is passed a single Error argument when called.The stream is not closed when the
'error:encryptor' event is emitted.#### Event:
'error:compressor'*
err: [<Error>][error]The
'error:compressor' event is emitted if an error occurred while encrypting raw data. The listener callback is passed a single Error argument when called.The stream is not closed when the
'error:compressor' event is emitted.
$3
*
key: [<string>][string] | [<Buffer>][buffer]
* opts: <zlib options>Create an EAES Decryptor Stream.
Data piped in here is decrypted and decompressed with the
key configuration.EAES Streams are encrypted, compressed streams that are tailored to the algorithm in this repo.
The
opts object are passed directly into [zlib.Gunzip][gunzip]#### Event:
'error'*
err: [<Error>][error]
* code: [<number>][number]This is emitted by either the decompression or decryption process.
code is 1 when emitted by the decryption engine and [undefined][undefined] otherwise.Catch errors explicitly with the
'error:decompressor' and 'error:decryptor' events.#### Event:
'error:decryptor'*
err: [<Error>][error]The
'error:decryptor' event is emitted if an error occurred while decrypting decompressed data. The listener callback is passed a single Error argument when called.The stream is not closed when the
'error:decryptor' event is emitted.#### Event:
'error:decompressor'*
err: [<Error>][error]The
'error:decompressor' event is emitted if an error occurred while decrypting raw data. The listener callback is passed a single Error argument when called.The stream is not closed when the
'error:decompressor' event is emitted.$3
*
infile: [<string>][string] | [<buffer>][buffer] | [<url>][url]
* outfile: [<string>][string] | [<buffer>][buffer] | [<url>][url]
* key: [<string>][string] | [<Buffer>][buffer]
* Returns: <fs.WriteStream>Read the file, compress and encrypt each chunk, write to the outfile.
Returns the
outputfile's stream object.$3
*
infile: [<string>][string] | [<buffer>][buffer] | [<url>][url]
* outfile: [<string>][string] | [<buffer>][buffer] | [<url>][url]
* key: [<string>][string] | [<Buffer>][buffer]
* Returns: <fs.WriteStream>Read the file, decrypt and decompress each chunk, write to the outfile.
Returns the
outputfile's stream object.ClI Info
* When using pipes, it's not possible to seek through the stream
* To avoid the terminal being cluttered while using pipes, direct other chained binaries (
stdout, stderr) to /dev/null` bash
Watching from an encrypted movie, hiding vlc's log information
$ libeaes dec movie.enc | vlc - > /dev/null 2>&1
`Development
$3
Feel free to clone, use in adherance to the license and perhaps send pull requests
` bash
git clone https://github.com/miraclx/libeaes-js.git
cd libeaes-js
npm install
hack on code
npm run build
npm test
`$3
Tests are executed with [Jest][jest]. To use it, simple run
npm install, it will install
Jest and its dependencies in your project's node_modules directory followed by npm run build and finally npm test.To run the tests:
`bash
npm install
npm run build
npm test
``[Apache 2.0][license] © Miraculous Owonubi ([@miraclx][author-url]) <omiraculous@gmail.com>
[npm]: https://github.com/npm/cli "The Node Package Manager"
[jest]: https://github.com/facebook/jest "Delightful JavaScript Testing"
[license]: LICENSE "Apache 2.0 License"
[author-url]: https://github.com/miraclx
[npm-url]: https://npmjs.org/package/libeaes
[npm-image]: https://badgen.net/npm/node/libeaes
[npm-image-url]: https://nodei.co/npm/libeaes.png?stars&downloads
[downloads-url]: https://npmjs.org/package/libeaes
[downloads-image]: https://badgen.net/npm/dm/libeaes
[url]: https://nodejs.org/api/url.html#url_the_whatwg_url_api
[buffer]: https://nodejs.org/api/buffer.html#buffer_class_buffer
[number]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type
[string]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type
[undefined]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Undefined_type
[gzip]: https://nodejs.org/api/zlib.html#zlib_class_zlib_gzip
[gunzip]: https://nodejs.org/api/zlib.html#zlib_class_zlib_gunzip
[error]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error
[object]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object