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

cipher-utility

v1.0.1

Published

A secure text encryption utility library using AES-GCM with Scrypt key derivation and AAD support

Readme

cipher-utility

MIT License

A utility library for robust and secure cryptographic operations using Node.js crypto module. It provides easy-to-use methods for encrypting and decrypting text with AES-GCM, leveraging Scrypt for key derivation.

Features

  • Strong Encryption: Uses AES-GCM ( Galois/Counter Mode) which provides both confidentiality and authenticity. Supports aes-256-gcm, aes-192-gcm, and aes-128-gcm.
  • Secure Key Derivation: Employs scryptSync for deriving encryption keys from passwords, offering protection against brute-force attacks.
  • Random Salt & IV: Automatically generates a unique salt and initialization vector (IV) for each encryption operation, enhancing security.
  • Additional Authenticated Data (AAD): Supports AAD to ensure the integrity of non-confidential data alongside the encrypted payload.
  • Customizable Parameters: Allows configuration of Scrypt parameters (N, r, p) for fine-tuning security vs. performance.
  • Flexible Encodings: Supports base64 and hex encodings for encrypted data, IV, tag, and salt.
  • Type-Safe: Written in TypeScript with comprehensive type definitions.
  • Error Handling: Gracefully handles decryption failures (e.g., wrong password, corrupted data) by returning null.

Installation

npm install cipher-utility
# or
yarn add cipher-utility
# or
bun add cipher-utility

Usage

import { Cipher } from 'cipher-utility';

const cipher = new Cipher();

const text = 'This is a secret message!';
const password = 'super-strong-password123';

// Encrypt
const encrypted = cipher.encrypt(text, password);

// Decrypt
const decrypted = cipher.decrypt(encrypted, password);

console.log('Decrypted:', decrypted); // Output: This is a secret message!

API

new Cipher(params?: ScryptParams)

Creates a new Cipher instance.

  • params (optional): An object to customize Scrypt parameters.
    • N: CPU/memory cost parameter (default: 4096).
    • r: Block size (default: 8).
    • p: Parallelization parameter (default: 1).

Note: The key length is automatically determined based on the algorithm used (16 bytes for AES-128, 24 bytes for AES-192, 32 bytes for AES-256).

cipher.encrypt(text, password, algorithm?, encoding?, aad?)

Encrypts the input text.

  • text: string: The plaintext to encrypt.
  • password: string: The password to derive the encryption key.
  • algorithm?: CipherGCMTypes: The AES-GCM algorithm to use (default: 'aes-256-gcm'). Supported: 'aes-256-gcm', 'aes-192-gcm', 'aes-128-gcm'.
  • encoding?: Encoding: The encoding for the output strings (encrypted, iv, tag, salt) (default: 'base64'). Supported: 'base64', 'hex'.
  • aad?: string: Optional Additional Authenticated Data.
  • Returns: EncryptedData object:
    type EncryptedData = {
      encrypted: string; // The encrypted text
      iv: string;        // The initialization vector
      tag: string;       // The authentication tag
      salt: string;      // The salt used for key derivation
      aad?: string;     // The AAD, if provided
    };

cipher.decrypt(encryptedData, password, algorithm?, encoding?)

Decrypts the encrypted data.

  • encryptedData: EncryptedData: The object returned by the encrypt method.
  • password: string: The password used for encryption.
  • algorithm?: CipherGCMTypes: The AES-GCM algorithm used for encryption (default: 'aes-256-gcm').
  • encoding?: Encoding: The encoding used for the input strings in encryptedData (default: 'base64').
  • Returns: string | null: The decrypted plaintext, or null if decryption fails (e.g., wrong password, tampered data, incorrect AAD).

Development

Prerequisites

  • Node.js (LTS recommended)
  • Bun (for running scripts, optional if you prefer npm/yarn)

Setup

  1. Clone the repository:
    git clone https://github.com/liorcodev/cipher-utility.git
    cd cipher-utility
  2. Install dependencies:
    bun install
    # or
    npm install

Scripts

  • bun run format: Format code using Prettier.
  • bun run dev: Run index.ts in watch mode (useful for quick testing).
  • bun run build: Build the library using tsup. Output is in the dist folder.
  • bun test: Run tests using Bun's test runner (tests are in src/cipher.test.ts).

Contributing

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

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE file for more information.