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

@codegeekdevs/encrypt-decrypt-file

v1.0.5

Published

Simple file encryption and decryption using AES-256-GCM with password-based key derivation

Downloads

13

Readme

encrypt-decrypt-file

Simple file encryption and decryption using AES-256-GCM with password-based key derivation (scrypt).

Features

  • Strong Encryption: Uses AES-256-GCM for authenticated encryption
  • Secure Key Derivation: Implements scrypt for password-based key derivation
  • Simple API: Easy-to-use functions for encrypting and decrypting files
  • CLI Support: Can be used as a command-line tool
  • Node.js Native: Built with Node.js crypto module (Node 18+)

Installation

npm install @codegeekdevs/encrypt-decrypt-file

Usage

As a Module

const { encryptFile, decryptFile } = require('encrypt-decrypt-file');

// Encrypt a file
encryptFile('./myfile.txt', 'my-secret-password', './myfile.txt.enc');

// Decrypt a file
decryptFile('./myfile.txt.enc', 'my-secret-password', './myfile-decrypted.txt');

As a CLI Tool

# Encrypt a file
node encrypt-decrypt-file.js encrypt ./myfile.txt "my-secret-password"

# Decrypt a file
node encrypt-decrypt-file.js decrypt ./myfile.txt.enc "my-secret-password"

# Specify custom output path
node encrypt-decrypt-file.js encrypt ./myfile.txt "my-secret-password" ./custom-output.enc

API

encryptFile(inputPath, password, outputPath)

Encrypts a file using AES-256-GCM.

Parameters:

  • inputPath (string): Path to the file to encrypt
  • password (string): Password for encryption
  • outputPath (string, optional): Output path for encrypted file. Defaults to ${inputPath}.enc

Returns: String - Path to the encrypted file

Example:

const outputPath = encryptFile('./document.pdf', 'super-secret-password');
console.log(`File encrypted at: ${outputPath}`);

decryptFile(inputPath, password, outputPath)

Decrypts a file that was encrypted with encryptFile.

Parameters:

  • inputPath (string): Path to the encrypted file
  • password (string): Password used for encryption
  • outputPath (string, optional): Output path for decrypted file. Auto-generated if not provided

Returns: String - Path to the decrypted file

Example:

const outputPath = decryptFile('./document.pdf.enc', 'super-secret-password');
console.log(`File decrypted at: ${outputPath}`);

Technical Details

Encryption Algorithm

  • Algorithm: AES-256-GCM (Galois/Counter Mode)
  • Key Length: 256 bits (32 bytes)
  • IV Length: 96 bits (12 bytes)
  • Auth Tag: 128 bits (16 bytes)

Key Derivation

  • Function: scrypt
  • Parameters:
    • N: 16384
    • r: 8
    • p: 1
    • Salt: 128 bits (16 bytes, randomly generated)

File Format

Encrypted files have the following structure:

[ "ENC1" (4 bytes) | SALT (16 bytes) | IV (12 bytes) | CIPHERTEXT | AUTH TAG (16 bytes) ]

The "ENC1" magic bytes allow for format versioning.

Requirements

  • Node.js 18.0.0 or higher

Security Considerations

  • Always use strong, unique passwords
  • Keep your passwords secure and never commit them to version control
  • The security of the encrypted data depends entirely on the strength of your password
  • Use environment variables or secure vaults for password management in production

License

MIT

Contributing

Issues and pull requests are welcome!

Author

David Faltermier, CodeGeek