npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@fnet/decrypt-and-unzip

v0.1.8

Published

A simple utility to decrypt and unzip a file or directory

Downloads

316

Readme

@fnet/decrypt-and-unzip

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.

How It Works

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.

Key Features

  • 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.

Conclusion

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.

@fnet/decrypt-and-unzip Developer Guide

Overview

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.

Installation

To install the library, use either npm or yarn:

npm install @fnet/decrypt-and-unzip

or

yarn add @fnet/decrypt-and-unzip

Usage

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.

Function Signature

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.

Example Usage

Extract Files to 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);
  }
})();

Extract Files to Disk

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);
  }
})();

Examples

Example 1: Decrypting and Unzipping to Memory

Decrypt and process the contents of an encrypted file in memory without creating temporary files on disk.

Example 2: Decrypting and Unzipping to a Directory

Decrypt an encrypted archive and extract its contents to a specified directory, organizing files exactly as structured in the archive.

Acknowledgement

This library utilizes unzipper for handling extraction of ZIP files.

Input Schema

$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