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

fortencrypt

v1.0.2

Published

Node.js encryption library made effortless — configure once, encrypt everywhere. TypeScript-ready, CLI-ready, secure AES-256-GCM and digital signature support.

Readme

FortEncrypt

FortEncrypt is a comprehensive encryption library and CLI tool for Node.js that provides robust cryptographic operations with an intuitive interface. It supports multiple encryption algorithms, compression, and additional authenticated data (AAD) for enhanced security.

Features

  • Multiple encryption algorithms: AES-256-GCM and ChaCha20-Poly1305
  • Configurable encryption settings (algorithm, encoding, compression)
  • Additional Authenticated Data (AAD) support
  • File and directory encryption/decryption
  • Key generation and management
  • Interactive command-line interface
  • Progress indicators for large operations
  • Comprehensive error handling

Installation

Install the package globally for CLI usage:

npm install -g fortencrypt

Or install locally as a dependency:

npm install fortencrypt

Quick Start

Generate an Encryption Key

fortencrypt generate-key -o master.key

Encrypt a File

fortencrypt encrypt -i secret.txt -o secret.enc -k master.key

Decrypt a File

fortencrypt decrypt -i secret.enc -o secret.txt -k master.key

CLI Usage

Generate Key Command

fortencrypt generate-key [options]

Options:

  • -o, --output <file>: Output file for the key (default: master.key)
  • -l, --length <length>: Key length in bytes (default: 32)
  • -f, --force: Overwrite existing key file

Encrypt Command

fortencrypt encrypt [input] [options]

Options:

  • -i, --input <file>: Input file to encrypt
  • -t, --text <text>: Text to encrypt
  • -o, --output <file>: Output file for encrypted data
  • -k, --key <key>: Encryption key (hex, file path, or env:VAR_NAME)
  • -a, --algorithm <algorithm>: Encryption algorithm (default: aes-256-gcm)
  • -e, --encoding <encoding>: Output encoding (default: hex)
  • -c, --compress: Enable compression
  • --aad <data>: Additional authenticated data
  • --stringify: Output as JSON string
  • -r, --recursive: Encrypt directory recursively

Decrypt Command

fortencrypt decrypt [input] [options]

Options:

  • -i, --input <file>: Input file to decrypt
  • -t, --text <text>: Text to decrypt
  • -o, --output <file>: Output file for decrypted data
  • -k, --key <key>: Decryption key (hex, file path, or env:VAR_NAME)
  • --aad <data>: Additional authenticated data
  • --buffer: Return result as buffer
  • -r, --recursive: Decrypt directory recursively

Interactive Mode

fortencrypt interactive

Launches an interactive wizard for encryption and decryption operations.

Programmatic API

Basic Usage

import CryptoLib from 'fortencrypt';

// Initialize with environment key
const crypto = new CryptoLib();
crypto.initialize();

// Encrypt data
const encrypted = await crypto.encrypt('Sensitive data');
console.log(encrypted);

// Decrypt data
const decrypted = await crypto.decrypt(encrypted);
console.log(decrypted); // 'Sensitive data'

Custom Configuration

import CryptoLib from 'fortencrypt';

const crypto = new CryptoLib({
  algorithm: 'chacha20-poly1305',
  outputEncoding: 'base64',
  compression: true,
});

// Initialize with custom key
crypto.initialize('your-32-byte-hex-key-here');

const data = { message: 'Hello, World!', number: 42 };

const encrypted = await crypto.encrypt(data);
const decrypted = await crypto.decrypt(encrypted);

console.log(decrypted); // { message: 'Hello, World!', number: 42 }

Using AAD (Additional Authenticated Data)

const crypto = new CryptoLib();
crypto.initialize();

const aad = 'authenticated-data';

const encrypted = await crypto.encrypt('secret message', { aad });
const decrypted = await crypto.decrypt(encrypted, { aad });

console.log(decrypted); // 'secret message'

Key Management

import { generateAndSaveKey, CryptoLib } from 'fortencrypt';

// Generate and save a key
const key = await generateAndSaveKey('master.key', 32);
console.log(key.toString('hex'));

// Derive a key from a password
const salt = CryptoLib.generateKey(16);
const derivedKey = CryptoLib.deriveKey('my-password', salt, 100000, 32);

Environment Configuration

Set the master key as an environment variable for automatic initialization:

export MASTER_KEY=your_32_byte_hex_master_key_here

Or create a .env file in your project root:

MASTER_KEY=your_32_byte_hex_master_key_here

Examples

Encrypt a Directory Recursively

fortencrypt encrypt -i documents/ -o encrypted_documents/ -k master.key -r

Decrypt with AAD

fortencrypt decrypt -i data.enc -o data.txt -k master.key --aad "auth-data"

Use Environment Key

export MASTER_KEY=$(cat master.key)
fortencrypt encrypt -i file.txt -o file.enc

API Reference

CryptoLib Class

Constructor

new CryptoLib(config?: Partial<CryptoConfig>): CryptoLib

Creates a new CryptoLib instance with optional configuration.

Methods

  • initialize(masterKey?: string | Buffer | null, encoding?: BufferEncoding): void
  • setMasterKey(masterKey: string | Buffer, encoding?: BufferEncoding): void
  • encrypt(input: any, options?: Partial<CryptoConfig>): Promise<EncryptionResult | string>
  • decrypt(payload: EncryptionResult | string, options?: Partial<CryptoConfig>): Promise<any>

Static Methods

  • generateKey(length?: number): Buffer
  • deriveKey(password: string, salt: Buffer, iterations?: number, length?: number): Buffer

Helper Functions

  • createCryptoLib(config?: Partial<CryptoConfig>): CryptoLib
  • generateAndSaveKey(filePath: string, length?: number): Promise<Buffer>
  • loadConfig(filePath: string): Promise<Record<string, any>>

Testing

Run the test suite:

npm test

Security Considerations

  • Always use strong, randomly generated keys
  • Protect encryption keys with appropriate access controls
  • Regularly rotate encryption keys for sensitive data
  • Use Additional Authenticated Data (AAD) when appropriate
  • Validate decrypted data before use

License

MIT