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

@arraypress/crypto

v1.0.0

Published

AES-256-GCM encrypt/decrypt with PBKDF2 key derivation. Zero dependencies, Web Crypto API.

Readme

@arraypress/crypto

AES-256-GCM encryption with PBKDF2 key derivation. Zero dependencies, Web Crypto API.

Uses the Web Crypto API — works in Cloudflare Workers, Node.js 20+, Deno, Bun, and browsers.

Installation

npm install @arraypress/crypto

Usage

import { encrypt, decrypt, sha256, secureCompare, randomToken } from '@arraypress/crypto';

// Encrypt and decrypt
const encrypted = await encrypt('sk_live_abc123', 'my-secret');
const decrypted = await decrypt(encrypted, 'my-secret');
// => 'sk_live_abc123'

// Hash
const hash = await sha256('my-session-token');

// Constant-time comparison
const match = secureCompare(apiKey, storedKey);

// Random token
const token = randomToken(); // 43-char base64url string

API

encrypt(plaintext, secret, options?)

Encrypt a string using AES-256-GCM with PBKDF2 key derivation. Returns a base64url-encoded string containing the IV prepended to the ciphertext. The same plaintext encrypted twice produces different outputs (random IV).

function encrypt(plaintext: string, secret: string, options?: KeyOptions): Promise<string>

Options:

| Option | Type | Description | | ------------ | -------- | ------------------------------------------------------ | | salt | string | Salt for PBKDF2 (default: 'arraypress-crypto-v1'). | | iterations | number | PBKDF2 iterations (default: 100000). |

const encrypted = await encrypt('sk_live_abc123', 'my-encryption-secret');

// Custom key derivation
const encrypted = await encrypt('sensitive-data', 'my-secret', {
  salt: 'my-app-salt',
  iterations: 200_000,
});

decrypt(encrypted, secret, options?)

Decrypt a base64url-encoded ciphertext produced by encrypt(). Options must match those used during encryption.

function decrypt(encrypted: string, secret: string, options?: KeyOptions): Promise<string>

Options: Same as encrypt().

const decrypted = await decrypt(encrypted, 'my-encryption-secret');
// => 'sk_live_abc123'

Throws an Error if decryption fails (wrong key, corrupted data, etc).

sha256(input)

Hash a string using SHA-256. Returns a hex-encoded string.

function sha256(input: string): Promise<string>
const hash = await sha256('my-session-token');
// => 'a1b2c3d4e5f6...'

secureCompare(a, b)

Constant-time string comparison to prevent timing attacks. Returns false if either argument is not a string or if lengths differ.

function secureCompare(a: string, b: string): boolean
if (secureCompare(providedKey, storedKey)) {
  // Authenticated
}

randomToken(bytes?)

Generate a cryptographically random base64url-encoded string.

function randomToken(bytes?: number): string

| Parameter | Type | Default | Description | | --------- | -------- | ------- | ---------------------- | | bytes | number | 32 | Number of random bytes |

const token = randomToken();    // 32 bytes = 43 chars
const short = randomToken(16);  // 16 bytes = 22 chars

deriveKey(secret, options?)

Derive an AES-256 CryptoKey from a secret string using PBKDF2. Used internally by encrypt() and decrypt(), but exported for advanced use cases.

function deriveKey(secret: string, options?: KeyOptions): Promise<CryptoKey>

Options: Same as encrypt().

const key = await deriveKey('my-secret', {
  salt: 'custom-salt',
  iterations: 200_000,
});

License

MIT