Overview
Database encryption protects:- Message history and content
- Group metadata and membership
- User identity and installation keys
- Consent preferences
- All local XMTP data
Enabling Encryption
Basic Encryption Setup
Provide a 32-byte encryption key when creating the database:Without Encryption
For testing or non-sensitive environments:If you create a database without encryption, you cannot add encryption later without recreating the database.
Key Generation
Secure Random Key
Generate a cryptographically secure key:Derive from Password
Derive a key from a user password using a KDF:Platform-Specific Storage
Store encryption keys securely using platform keychains:- iOS (Keychain)
- Android (Keystore)
- Node.js
SQLCipher Configuration
Verify SQLCipher Support
Check if SQLCipher is available:Custom Cipher Settings
SQLCipher uses secure defaults, but you can customize if needed:The default SQLCipher settings provide strong security. Only modify cipher settings if you have specific security requirements and understand the implications.
TypeScript (Node.js) Examples
Key Rotation
Migrate to New Key
Best Practices
Platform Considerations
Native (iOS/Android)
SQLCipher is fully supported:WebAssembly
Encryption is not supported in WASM:In WASM environments, the database is stored in IndexedDB without encryption. Consider this when handling sensitive data in web applications.
Troubleshooting
Database Won’t Open
Performance Impact
Encryption adds minimal overhead:Key Size Errors
Next Steps
Creating Clients
Learn how to create clients with encrypted storage
Consent Management
Manage user preferences and privacy
