A lightweight Node.js utility for compressing and encrypting files or buffers — and for decompressing and decrypting them later.
It wraps Node’s native zlib and crypto modules to provide a simple async API for secure, stream-based ZIP operations.
- 🔒 AES-256-CBC encryption with password protection
- 🗜️ Gzip compression/decompression
- 💾 Works with buffers, strings, or files
- ⚙️ Stream-based design for efficiency
- 🧩 Promise-based (async/await friendly)
npm install cryptozip(Or just copy cryptozip.js into your project if you prefer a standalone file.)
const { zip, unzip } = require('./cryptozip');Compress a string or file, optionally with a password.
const { zip } = require('./cryptozip');
(async () => {
const data = 'Hello Secure World!';
const zipped = await zip(data, { password: 'mySecret123' });
console.log('Compressed & encrypted buffer:', zipped);
})();await zip({ file: 'input.txt' }, { password: 'mypwd', outputFile: 'output.gzenc' });const { unzip } = require('./cryptozip');
(async () => {
const decrypted = await unzip(zipped, { password: 'mySecret123' });
console.log(decrypted.toString());
})();await unzip({ file: 'output.gzenc' }, { password: 'mypwd', outputFile: 'restored.txt' });| Parameter | Type | Description |
|---|---|---|
input |
string | Buffer | { file: string } |
Input data or path to file to compress |
options.password |
string (optional) |
Encrypt with AES-256-CBC using this password |
options.outputFile |
string (optional) |
If set, write result to this file |
| Returns | Promise<Buffer | undefined> |
Returns compressed buffer (if no outputFile) or writes to disk |
| Parameter | Type | Description |
|---|---|---|
input |
Buffer | { file: string } |
Input data or file path to decompress |
options.password |
string (optional) |
Decrypt with AES-256-CBC using this password |
options.outputFile |
string (optional) |
If set, write result to this file |
| Returns | Promise<Buffer | undefined> |
Returns decompressed buffer or writes to disk |
- AES-256-CBC encryption is used, with a random IV stored at the start of the file/buffer.
- When
outputFileis used, no buffer is returned — data is written directly to disk. - The password must be the same for compression and decompression.
You can quickly test it in Node REPL or add a simple CLI:
node -e "const {zip, unzip}=require('./cryptozip');(async()=>{await zip({file:'a.txt'},{password:'123',outputFile:'a.gzenc'})})();"MIT © 2025