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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@bouzraa/files-protector

v1.2.0

Published

A package for encrypting and decrypting files using various algorithms.

Readme

Files Protector

Files Protector is a TypeScript/Node.js package that provides robust functionality for encrypting and decrypting files using various cryptographic algorithms. This package allows you to easily secure and restore files through AES encryption and decryption with initialization vectors for enhanced security.

Table of Contents

Installation

To install Files Protector, use npm:

npm install files-protector

Usage

Encrypting a File

import { FilesProtector } from "files-protector";

const encryptionKey = "your-encryption-key-in-hex";
const protector = new FilesProtector(encryptionKey);

const inputPath = "path/to/your/input/file.txt";
const outputPath = "path/to/your/encrypted/file.enc";

protector.encryptFile(inputPath, outputPath);

Decrypting a File

import { FilesProtector } from "files-protector";

const encryptionKey = "your-encryption-key-in-hex";
const protector = new FilesProtector(encryptionKey);

const inputPath = "path/to/your/encrypted/file.enc";
const outputPath = "path/to/your/decrypted/file.txt";

protector.decryptFile(inputPath, outputPath);

API

FilesProtector

Constructor

constructor(encryptionKey: string, algorithm: string = "aes-256-ctr")
  • encryptionKey: A hexadecimal string used for encryption and decryption.
  • algorithm: (optional) The algorithm to use for encryption. Default is "aes-256-ctr".

Methods

encryptFile(inputFilePath: string, outputFilePath: string): void

Encrypts the file at inputFilePath and writes the encrypted content to outputFilePath. Uses an initialization vector (IV) for enhanced security.

decryptFile(inputFilePath: string, outputFilePath: string): string

Decrypts the file at inputFilePath and writes the decrypted content to outputFilePath. Returns the output file path.

Private Methods

The class also includes two private methods for internal use:

  • private encrypt(buffer: Buffer): Buffer
  • private decrypt(encryptedBuffer: Buffer): Buffer

These methods handle the actual encryption and decryption operations using initialization vectors for secure cryptographic operations.

Security Features

  • Utilizes initialization vectors (IV) for enhanced security
  • IV is automatically generated for each encryption operation
  • IV is stored with the encrypted data for proper decryption
  • Supports various AES encryption algorithms
  • Implements secure buffer handling

Supported Algorithms

The following algorithms are supported:

  • aes-256-ctr (default)
  • aes-192-ctr
  • aes-128-ctr
  • aes-256-cbc
  • aes-192-cbc
  • aes-128-cbc

Ensure that your encryption key length matches the requirements for the selected algorithm.

Error Handling

The package includes comprehensive error handling:

  • File reading/writing errors are caught and logged
  • Encryption/decryption errors are properly handled
  • All errors are logged with appropriate messages
  • Errors are propagated to the caller for proper handling

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. Make sure to:

  1. Follow the existing code style
  2. Add/update tests as needed
  3. Update documentation for any new features
  4. Ensure all tests pass before submitting

License

This package is licensed under the MIT License. See the LICENSE file for details.


For more detailed documentation and updates, visit the project's repository.

Key Features:

  • Type Safety: Written in TypeScript for better development experience
  • Secure Implementation: Uses crypto module with initialization vectors
  • Flexible: Supports multiple encryption algorithms
  • Error Handling: Comprehensive error management
  • Easy to Use: Simple API for file encryption and decryption