This project provides a straightforward solution for decrypting and unzipping files that have been encrypted using AES-GCM. It is designed to help users seamlessly access and extract contents from encrypted ZIP files, either storing them directly to memory or saving them to a specified location on disk.
The tool operates by taking an encrypted file or buffer and a private key as inputs. Using AES-256-GCM encryption, it carefully decrypts the file. After decryption, it extracts the contents of the decrypted ZIP file. If an output path is provided, files are saved to that location on disk, otherwise, they are stored in memory and returned as an object.
- Decryption with AES-GCM: Ensures secure decryption of files using a specified private key.
- Flexible Input Handling: Supports both file paths and buffer inputs for encrypted content.
- ZIP Extraction: Retrieves and processes contents inside ZIP files.
- Output Flexibility: Provides options to store extracted files either in memory or on disk.
In summary, this project offers a reliable and efficient means to decrypt and unzip files securely. Whether you need to handle files in-memory for quick access or extract them to disk for further use, this tool caters to both needs without any unnecessary complexity.
The @fnet/decrypt-and-unzip
library provides a straightforward solution for decrypting a file encrypted with AES-GCM and unzipping its contents. Whether you need to handle files in memory or extract them to disk, this library simplifies the process into a single function call.
To install the library, use either npm or yarn:
npm install @fnet/decrypt-and-unzip
or
yarn add @fnet/decrypt-and-unzip
The core functionality of this library is provided by the decryptAndUnzip
function. It allows you to decrypt and unzip files using a private key. The function supports two modes: extracting files to memory or to a specified output directory on disk.
decryptAndUnzip({ privateKey, input, output })
-
privateKey
: A hex-encoded string representing the private key used for decryption. -
input
: A string specifying the file path of the encrypted file or a Buffer with the encrypted content. -
output
: An optional string specifying the directory where the files will be extracted. If omitted, files will be returned in memory.
import decryptAndUnzip from '@fnet/decrypt-and-unzip';
(async () => {
const privateKey = 'your-hex-encoded-private-key';
const inputFilePath = 'path/to/encrypted-file.enc';
try {
const filesInMemory = await decryptAndUnzip({ privateKey, input: inputFilePath });
console.log('Decrypted files:', filesInMemory);
} catch (error) {
console.error('Failed to decrypt and unzip:', error);
}
})();
import decryptAndUnzip from '@fnet/decrypt-and-unzip';
(async () => {
const privateKey = 'your-hex-encoded-private-key';
const inputFilePath = 'path/to/encrypted-file.enc';
const outputDirectory = 'path/to/extracted-files';
try {
const outputPath = await decryptAndUnzip({ privateKey, input: inputFilePath, output: outputDirectory });
console.log(`Files extracted to: ${outputPath}`);
} catch (error) {
console.error('Error during decryption and extraction:', error);
}
})();
Decrypt and process the contents of an encrypted file in memory without creating temporary files on disk.
Decrypt an encrypted archive and extract its contents to a specified directory, organizing files exactly as structured in the archive.
This library utilizes unzipper
for handling extraction of ZIP files.
$schema: https://json-schema.org/draft/2020-12/schema
title: DecryptAndUnzipInput
type: object
properties:
privateKey:
type: string
description: The private key used for decryption (hex encoded).
input:
oneOf:
- type: string
description: The input file path where the encrypted content is located.
- type: string
contentEncoding: base64
description: The Buffer with encrypted content.
output:
type: string
description: The output folder where files will be extracted (only used when
mode is 'disk').
required:
- privateKey
- input