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/zip-and-encrypt

v0.1.12

Published

A simple utility to encrypt and zip a file or directory

Downloads

30

Readme

@fnet/zip-and-encrypt

This project provides a simple utility for encrypting and zipping the contents of a folder using AES-GCM encryption. It is designed to securely store or transfer folder contents by combining compression and encryption into a single step.

How It Works

The tool accepts a folder as input, compresses its contents into a ZIP file, and then encrypts the file using AES-256-GCM. You can choose to either save the encrypted file to disk or return it as a memory buffer.

Key Features

  • Folder Compression: Compresses an entire folder into a single ZIP archive.
  • AES-256-GCM Encryption: Utilizes modern cryptography standards for secure encryption.
  • Flexible Output: Allows encrypted content to be saved as a file or used directly in memory.
  • Error Handling: Provides feedback on errors related to input validation and processing.

Conclusion

The @fnet/zip-and-encrypt utility is a straightforward solution for those needing to compress and encrypt folder contents quickly and securely. It's useful for protecting sensitive data during storage or transmission without unnecessary complexity.

Developer Guide for @fnet/zip-and-encrypt

Overview

The @fnet/zip-and-encrypt library provides a straightforward way to compress and encrypt directories using AES-GCM encryption. By taking a specified directory and a private key, the library can create a secure, encrypted zip file. This is ideal for securely archiving data that needs to be kept confidential.

Installation

You can install the library using either npm or yarn:

npm install @fnet/zip-and-encrypt

or

yarn add @fnet/zip-and-encrypt

Usage

The main functionality is provided through a single function encryptAndZip, which zips the contents of a specified directory and encrypts the result. This function can be used to either return the encrypted data as a buffer or save it directly to disk.

Example Usage

Here's a basic example demonstrating how to use the encryptAndZip function:

import encryptAndZip from '@fnet/zip-and-encrypt';

// Define input parameters
const privateKey = 'yourhexencodedprivatekeyhere';
const inputDirectoryPath = './path/to/your/directory';
const outputPath = './path/to/your/output/encrypted.zip';

// Using the encryptAndZip function
encryptAndZip({ privateKey, input: inputDirectoryPath, output: outputPath })
  .then((result) => {
    console.log('Encrypted file successfully created:', result);
  })
  .catch((error) => {
    console.error('An error occurred:', error);
  });

In this example, the function takes a private key, an input directory, and an optional output path. If an output path is specified, the encrypted zip is saved to disk. If not, the encrypted content is returned as a Buffer.

Memory Mode

If you prefer to handle the encrypted content directly in memory instead of saving it to disk, you can omit the output parameter:

encryptAndZip({ privateKey, input: inputDirectoryPath })
  .then((encryptedBuffer) => {
    console.log('Encrypted content as Buffer:', encryptedBuffer);
  })
  .catch((error) => {
    console.error('An error occurred:', error);
  });

Examples

Encrypt a Directory with Output to Disk

encryptAndZip({
  privateKey: 'yourhexencodedprivatekeyhere',
  input: './path/to/directory',
  output: './encrypted/file.zip'
}).then((outputPath) => {
  console.log('File saved to:', outputPath);
}).catch(console.error);

Encrypt a Directory with Buffer Output

encryptAndZip({
  privateKey: 'yourhexencodedprivatekeyhere',
  input: './path/to/directory'
}).then((buffer) => {
  // Use the encrypted buffer as needed
  console.log('Encrypted buffer:', buffer);
}).catch(console.error);

Acknowledgement

This project relies on powerful tools such as Node.js' built-in crypto module and archiver for handling compression functionalities. These underpin the core features of @fnet/zip-and-encrypt, providing reliable encryption and zipping capabilities.

Input Schema

$schema: https://json-schema.org/draft/2020-12/schema
title: EncryptAndZipArguments
type: object
properties:
  privateKey:
    type: string
    description: The private key used for encryption (hex encoded).
  input:
    type: string
    description: The folder whose contents will be zipped and encrypted.
  output:
    type: string
    description: The output file path where the encrypted content will be saved. If
      not provided, returns the encrypted content as a Buffer.
required:
  - privateKey
  - input