SEA.work()
Perform proof-of-work computations using PBKDF2 (Password-Based Key Derivation Function 2) or compute SHA hashes. Primarily used for password hardening and key derivation.
Syntax
Parameters
- data (string|any): Data to process (password, string, or any JSON-serializable value)
- salt (string|buffer, optional): Salt for PBKDF2 (random if not provided)
- callback (function, optional): Called with result
- options (object, optional):
name: Algorithm name (default: ‘PBKDF2’, or ‘SHA-256’, ‘SHA-1’)
iterations: PBKDF2 iterations (default: 100,000)
length: Output length in bits (default: 512)
hash: Hash algorithm for PBKDF2 (default: SHA-256)
encode: Output encoding (default: ‘base64’)
salt: Alternative way to specify salt
Returns
A Promise that resolves to a base64-encoded string (or custom encoding).
Basic Usage
Proof-of-Work (PBKDF2)
With Specific Salt
SHA-256 Hashing
With Callback
How It Works
Reference: ~/workspace/source/sea/work.js:9-40
PBKDF2 Mode (Default)
SHA Mode
Use Cases
Password Hashing
Password Verification
Key Derivation for Encryption
Content Hashing
User Authentication
This is how SEA uses work() internally for user creation:
Reference: ~/workspace/source/sea/create.js:41-42
Options
Custom Iterations
Increase security (slower) or decrease for faster operations:
Custom Key Length
Different Hash Functions
Custom Encoding
PBKDF2 Details
Algorithm Parameters
Default PBKDF2 configuration:
Reference: ~/workspace/source/sea/settings.js:218
Security Level
- Iterations: 100,000 (as of 2024, OWASP recommends 600,000+ for passwords)
- Hash: SHA-256 (PRF - Pseudorandom Function)
- Salt: Minimum 9 bytes random
- Output: 64 bytes (512 bits)
Why PBKDF2?
- Slow by design: Computationally expensive to brute force
- Salting: Prevents rainbow table attacks
- Iteration count: Increases computational cost for attackers
- Standard: NIST approved (SP 800-132)
Timing
Iteration Impact
- 10,000 iterations: ~10ms
- 100,000 iterations: ~50-100ms (default)
- 500,000 iterations: ~250-500ms
- 1,000,000 iterations: ~500ms-1s
Higher iteration counts provide more security but increase authentication time. Balance security needs with user experience.
Security Considerations
Salt Requirements
- Uniqueness: Each password should have unique salt
- Randomness: Use cryptographically secure random
- Length: Minimum 8 bytes, 9+ recommended
- Storage: Store salt alongside hashed password
Password Strength
PBKDF2 hardens weak passwords but doesn’t make them strong:
Rainbow Tables
Salting prevents rainbow table attacks:
Timing Attacks
PBKDF2 is designed to be constant-time for the same iteration count.
Common Patterns
Secure Password Storage
Progressive Strengthening
Increase iterations over time:
Key Stretching
Data Integrity
Comparison with Alternatives
vs. bcrypt
- PBKDF2: NIST approved, Web Crypto native, widely supported
- bcrypt: Designed for passwords, memory-hard, not in Web Crypto API
vs. scrypt
- PBKDF2: Less memory-intensive, faster
- scrypt: Memory-hard, better against hardware attacks, not in Web Crypto API
vs. Argon2
- PBKDF2: Older, well-tested, native browser support
- Argon2: Modern, winner of password hashing competition, requires library
Error Handling
Browser Compatibility
Requires Web Crypto API support:
- Chrome/Edge 37+
- Firefox 34+
- Safari 11+
- Node.js with
@peculiar/webcrypto polyfill
PBKDF2 requires HTTPS in browsers (Web Crypto API security requirement).