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 🙏

© 2025 – Pkg Stats / Ryan Hefner

funkz-crypto

v1.0.1

Published

Provides cryptographic functionality for securely handling data — including hashing, encryption, decryption, signing, and verifying data — using algorithms like AES, RSA, and SHA.

Readme

funkz-crypto

A lightweight, dependency-free encryption module built on the Web Crypto API (window.crypto.subtle), designed for secure AES-GCM encryption, decryption, and SHA-256 hashing in TypeScript or JavaScript projects.


Features

  • 🔑 AES-GCM encryption and decryption
  • 🧮 SHA-256 hashing (sha256Hex)
  • 🎲 Secure random IV and key generation
  • 🧰 Fully typed (ICrypto interface)
  • 🌐 Works in modern browsers with window.crypto

Installation

npm i funkz-crypto

Example Usage

import Crypto, { sha256Hex, generateKeyData } from "funkz-crypto";

// Generate a random 16-byte IV
const iv = generateKeyData(16);

// Create a crypto instance with a secret key and IV
const cryptoInstance = new Crypto("my-secret-key", iv);

// Encrypt a message
const encrypted = await cryptoInstance.encrypt("Hello World!");
console.log("Encrypted (ArrayBuffer):", encrypted);

// Decrypt the message
const decrypted = await cryptoInstance.decrypt(encrypted);
console.log("Decrypted:", decrypted); // "Hello World!"

// Generate a SHA-256 hash
const hash = await sha256Hex("Hello World!");
console.log("SHA-256 Hash:", hash);

// Generate random bytes (for keys or IVs)
const randomBytes = generateKeyData(32);
console.log("Random bytes:", randomBytes);

Functions & Class Overview

Crypto class

Implements AES-GCM symmetric encryption using a UTF-8 encoded secret.

| Method | Description | | ---------------------------------- | ------------------------------------------------------- | | encrypt(message: string) | Encrypts a string using AES-GCM. Returns ArrayBuffer. | | decrypt(cipherText: ArrayBuffer) | Decrypts AES-GCM ciphertext. Returns plaintext string. |

Constructor

constructor(secret: string, iv?: Uint8Array)

  • secret: A UTF-8 string used as the encryption key.
  • iv: Optional initialization vector (IV). If not provided, one is auto-generated via generateKeyData().

Utility Functions

  • generateKeyData(len?: number): Uint8Array Generates a secure random byte array using crypto.getRandomValues().
  • sha256Hex(data: string): Promise Creates a SHA-256 hash in hexadecimal format.

Security Notes

IV reuse: Avoid reusing the same IV (_iv) with the same secret key for multiple encryptions. For better security, generate a new IV per message and store/transmit it alongside the ciphertext.

Key strength: AES-GCM supports 128, 192, and 256-bit keys. Ensure your secret string is long enough (e.g., 16+ characters for AES-128).

Environment: This module uses window.crypto.subtle. It is supported in all modern browsers and recent versions of Node.js (v20+ with Web Crypto).


Example — Encrypt/Decrypt with Dynamic IV

const iv = generateKeyData(12); // 96-bit IV (recommended for AES-GCM)
const cryptoInstance = new Crypto("super-secret-key", iv);

const ciphertext = await cryptoInstance.encrypt("Sensitive Data");
const plaintext = await cryptoInstance.decrypt(ciphertext);

console.log("Plaintext:", plaintext);

License

MIT © 2025 Ariel Francis Fernando Gacilo