Skip to content

feat: implement Web Crypto API encryption/decryption utilities #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 6, 2025

Conversation

nullcoder
Copy link
Owner

Summary

  • Implemented core encryption module using Web Crypto API for AES-GCM encryption
  • All functions are edge-runtime compatible for Cloudflare Workers

Implementation Details

Core Functions

  • generateEncryptionKey() - Generates 256-bit AES keys
  • exportKey()/importKey() - Base64url key serialization for URL safety
  • encrypt()/decrypt() - AES-GCM encryption with fresh IV generation
  • generateShareableUrl() - Creates shareable links with keys in fragments
  • extractKeyFromUrl() - Extracts keys from URL fragments

Key Features

  • ✅ Zero-knowledge encryption (keys never sent to server)
  • ✅ URL-safe base64url encoding
  • ✅ Large data support (chunked encoding to avoid stack overflow)
  • ✅ Comprehensive error handling with custom error classes
  • ✅ Full JSDoc documentation
  • ✅ 24 comprehensive tests with 100% coverage

Technical Decisions

  • Used Web Crypto API for edge compatibility
  • 256-bit AES-GCM with 12-byte IVs
  • Base64url encoding for URL safety
  • Chunked encoding for large data (fixes stack overflow)

Test Results

✓ 24 tests passed
✓ Handles large data (1MB+)
✓ Unicode and special characters
✓ Error cases (wrong key, corrupted data)
✓ URL generation and parsing

Closes #36

🤖 Generated with Claude Code

- Created lib/crypto.ts with AES-GCM encryption using Web Crypto API
- Implemented generateEncryptionKey() for 256-bit key generation
- Added exportKey() and importKey() for base64url key serialization
- Implemented encrypt() and decrypt() with fresh IV generation
- Added URL utilities for shareable link generation
- Created comprehensive test suite with 24 passing tests
- Fixed base64 encoding for large data (chunked encoding)
- All functions are edge-runtime compatible

Closes #36

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <claude@ghostpaste.dev>
Copy link

cloudflare-workers-and-pages bot commented Jun 6, 2025

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
ghostpaste 6edfc24 Visit preview Jun 06 2025, 08:09 AM

nullcoder and others added 2 commits June 6, 2025 00:59
- Changed EncryptedData interface to use Uint8Array instead of base64 strings
- Added packEncryptedBlob() and unpackEncryptedBlob() for blob storage format
- Added high-level encryptAndPack() and unpackAndDecrypt() convenience functions
- Storage format now matches spec: [12 bytes IV][Encrypted data]
- Reduces storage size by ~33% (eliminates base64 encoding overhead)
- Keys remain base64url encoded for URL sharing
- Updated all tests to work with binary data
- Added 7 new tests for blob packing/unpacking

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <claude@ghostpaste.dev>
- All Web Crypto API tasks completed
- Issue #36 fully implemented

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <claude@ghostpaste.dev>
@nullcoder nullcoder merged commit 5506a4a into main Jun 6, 2025
1 check was pending
@nullcoder nullcoder deleted the feat/crypto-module branch June 6, 2025 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: implement Web Crypto API encryption/decryption utilities
1 participant