Skip to content

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

Closed
@nullcoder

Description

@nullcoder

Description

Implement the core encryption module using Web Crypto API for AES-GCM encryption/decryption that works in Cloudflare Workers edge runtime.

Tasks

  • Create lib/crypto.ts with the following functions:
    • generateEncryptionKey() - Generate 256-bit AES key
    • exportKey(key: CryptoKey) - Export key to base64url
    • importKey(keyString: string) - Import base64url key
    • encrypt(data: Uint8Array, key: CryptoKey) - AES-GCM encryption with fresh IV
    • decrypt(encryptedData: Uint8Array, key: CryptoKey) - AES-GCM decryption
  • Implement proper error handling with custom error classes
  • Add JSDoc documentation for all functions
  • Create comprehensive unit tests

Technical Requirements

  • Use Web Crypto API (no Node.js crypto)
  • 256-bit AES-GCM encryption
  • 12-byte IV (crypto.getRandomValues)
  • Base64url encoding for URL safety
  • Edge runtime compatible

Acceptance Criteria

  • All crypto operations use Web Crypto API
  • Tests pass in edge runtime environment
  • Proper error handling for invalid keys/data
  • Type-safe implementation with TypeScript

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature implementationpriority: highShould be done soon

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions