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

encypher

v1.0.1

Published

A lightweight React hook for encrypted localStorage/sessionStorage with a useState-like API.

Readme

Encypher

A lightweight React hook for encrypted localStorage/sessionStorage with a useState-like API. Securely store sensitive data in the browser using AES-GCM (Web Crypto API), with an optional (insecure) XOR fallback for legacy environments.


Features

  • AES-GCM encryption (Web Crypto API)
  • Custom secret per hook or via context provider
  • Optional TTL (time-to-live) for expiring data
  • Works with localStorage, sessionStorage, or custom storage
  • Syncs across tabs/windows
  • XOR fallback for legacy browsers (not secure)
  • Easy API: [value, setValue, remove, reencrypt]
  • Tested with React 17/18

Installation

# npm install encypher
# or
# yarn add encypher

Usage

Basic Example

import { useEncryptedStorage } from "encypher";

function MyComponent() {
  const [user, setUser, removeUser] = useEncryptedStorage("user", null, {
    secret: "my-strong-secret",
    storage: "local", // or "session"
    ttl: 3600 * 1000, // 1 hour (optional)
  });

  // ...
}

With Provider (global secret)

import { EncryptedStorageProvider, useEncryptedStorage } from "encypher";

function App() {
  return (
    <EncryptedStorageProvider secret="my-global-secret">
      <MyComponent />
    </EncryptedStorageProvider>
  );
}

Custom Storage

const customStorage = {
  getItem: (key) => window.localStorage.getItem(key),
  setItem: (key, value) => window.localStorage.setItem(key, value),
  removeItem: (key) => window.localStorage.removeItem(key),
};

const [data, setData] = useEncryptedStorage("key", {}, { secret, storage: customStorage });

API

useEncryptedStorage(key, initialValue, options)

  • key (string): Storage key
  • initialValue (any): Initial value if not present
  • options (object):
    • secret (string): Encryption secret (required)
    • storage ("local" | "session" | object): Storage backend (default: "local")
    • ttl (number): Time-to-live in ms (optional)
    • fallback ("xor"): Use XOR fallback if AES unavailable (default: "xor")
    • onFallback (function): Called if fallback is used
    • onError (function): Called on error
    • onReencrypt (function): Called after re-encryption

Returns:
[value, setValue, remove, reencrypt]

  • value: Current value
  • setValue(val): Set and encrypt value (async)
  • remove(): Remove value from storage
  • reencrypt(newSecret): Re-encrypt with a new secret (async)

Security Notes

  • Always use a strong, unique secret.
  • The XOR fallback is insecure and should only be used for non-sensitive data or legacy support.
  • The secret is derived using PBKDF2 for AES-256, but you must still use a cryptographically strong secret.
  • Data is only as secure as the environment and the strength of your secret.

Limitations

  • Only works in browsers with the Web Crypto API for AES-GCM.
  • Only JSON-serializable values are supported.
  • Not suitable for highly sensitive or regulated data.

License

MIT


Contributing

PRs and issues welcome!


Author

Sreehari S J