Skip to content

Zero-dependency encryption library for JavaScript & TypeScript. Secure localStorage, sessionStorage, or any data with AES-256-GCM encryption. Production-ready with 93% test coverage.

License

Notifications You must be signed in to change notification settings

zemzemi/CryptoBox

CryptoBox

Secure encryption and storage for JavaScript & TypeScript.

npm version License: MIT TypeScript GitHub

Zero dependencies • AES-256-GCM • Type-safe • Cross-platform

Why CryptoBox?

  • 🔒 Secure by Default - Military-grade AES-256-GCM encryption
  • 📦 Zero Dependencies - No supply chain vulnerabilities
  • 🎯 Type-Safe - Full TypeScript support with strict typing
  • ✅ Production-Ready - 93% test coverage, battle-tested
  • ⚡ Simple API - 3 lines to encrypt localStorage
  • 🌐 Universal - Works in Browser, Node.js, Deno, and Bun

Install

npm install @azemzemi/cryptobox

Usage

import { createSecureLocalStorage } from '@azemzemi/cryptobox';

const storage = createSecureLocalStorage();

await storage.setSecure('user', { id: 123 }, 'password');
const user = await storage.getSecure('user', 'password');

Features

  • AES-256-GCM encryption with PBKDF2
  • Zero dependencies
  • Full TypeScript support
  • Browser, Node.js 18+, Deno, Bun
  • 93% test coverage

Use Cases

// Authentication tokens
await storage.setSecure('auth', { jwt: 'xxx', refresh: 'yyy' }, password);

// Sensitive user data
await storage.setSecure('payment', { cardLast4: '1234' }, password);

// Form auto-save
await storage.setSecure('draft', { title: 'Post', content: '...' }, password);

API

Storage

createSecureLocalStorage()      // Browser: localStorage
createSecureSessionStorage()    // Browser: sessionStorage
createSecureMemoryStorage()     // Universal: in-memory

Encryption

import { AesGcmEncryptor } from '@azemzemi/cryptobox';

const encryptor = new AesGcmEncryptor();
const encrypted = await encryptor.encrypt(data, 'password');
const decrypted = await encryptor.decrypt(encrypted, 'password');

Custom Storage

import { SecureStorage, AesGcmEncryptor, IStorage } from '@azemzemi/cryptobox';

class MyStorage implements IStorage {
  setItem(key: string, value: string): void { }
  getItem(key: string): string | null { return null; }
  removeItem(key: string): void { }
}

const storage = new SecureStorage(new MyStorage(), new AesGcmEncryptor());

Security

  • AES-256-GCM authenticated encryption
  • PBKDF2-HMAC-SHA256 (100,000 iterations)
  • Random salt and IV per operation
  • Timing-attack protection

See SECURITY.md for vulnerability reporting.

License

MIT

About

Zero-dependency encryption library for JavaScript & TypeScript. Secure localStorage, sessionStorage, or any data with AES-256-GCM encryption. Production-ready with 93% test coverage.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published