AshCrypt is a modular and efficient encryption library for handling large files using the AES-GCM encryption algorithm. It provides chunked encryption and decryption support using streams for memory-efficient processing, suitable for secure file handling and transmission.
The library divides files into configurable chunks (default 512 KB), encrypts each chunk separately, and appends essential metadata (salt, IV, tag) to each chunk.
- 🔐 AES-GCM encryption (128, 192, or 256-bit)
- 🧩 Configurable chunk size (default: 512KB)
- 📁 Stream-based I/O for large files
- 🔄 Parallel processing support for better performance
- 📦 Easy integration and usage via typed API
npm install ashcryptimport { AES, Stream } from 'ashcrypt';
const aes = new AES({ secret: 'my-very-secure-password' });
const stream = new Stream({ algorithm: aes });
// Encrypting a file
stream.read('input.txt', 'encrypt')
.pipe(stream.write('output.enc'))
.on('finish', () => {
// Decrypting a file
stream.read('output.enc', 'decrypt')
.pipe(stream.write('decrypted.txt'));
})Handles key derivation and encryption/decryption of buffers.
new AES({ secret, chunkSize, algorithm, iterations });secret: Password or passphrasechunkSize: (Optional): Default: 512 * 1000 (512KB)algorithm: (Optional): Default: 'aes-256-gcm'iterations: (Optional): Default: 100000 (PBKDF2 iterations)
Derives a key from the given salt using PBKDF2.
Returns the final size of a chunk after encryption (includes metadata).
Encrypts a single chunk. Appends salt + iv + tag to encrypted content.
Decrypts a previously encrypted chunk. Extracts and uses the appended metadata.
Provides stream-based encryption/decryption for large files.
new Stream({ algorithm, maxParallel });algorithm: Instance of AES (or compatible)maxParallel(optional): Number of parallel chunks to process (default: 1)
Creates a transform stream for encryption or decryption.
Returns a read stream piped through transformation (encryption/decryption).
Returns a write stream to save the final output.
Each chunk is encoded as:
[salt (16–32B)][IV (12B)][Auth Tag (16B)][Encrypted Data]
- Salt: Random bytes used for PBKDF2
- IV: Initialization vector
- Auth Tag: AES-GCM tag for integrity
- Encrypted Data: Ciphertext of the original chunk
Licensed under the MIT License. See LICENSE for details.