Overview
E2EE in LiveKit:- Encrypts media (audio/video) using frame encryption
- Encrypts data messages using data packet encryption
- Uses AES-GCM encryption algorithm
- Supports both shared key and per-participant key modes
- Keys are never sent to the LiveKit server
Setting Up E2EE
let encryptionOptions = EncryptionOptions(
keyProvider: keyProvider,
encryptionType: .gcm // AES-GCM encryption
)
let e2eeManager = E2EEManager(options: encryptionOptions)
Complete Example
Key Management
Setting Keys
For shared key mode:Ratcheting Keys
Ratchet keys for forward secrecy:Exporting Keys
Export keys for backup or sharing:Key Ring and Index
The key provider maintains a key ring (default size: 16):Advanced Configuration
Key Provider Options
Customize the key provider behavior:sharedKey: Use shared key mode (true) or per-participant mode (false)ratchetSalt: Salt for key ratchetingratchetWindowSize: Window size for automatic ratcheting (0 = disabled)uncryptedMagicBytes: Magic bytes to identify unencrypted framesfailureTolerance: Number of decryption failures to toleratekeyRingSize: Maximum number of keys in the ring
Enable/Disable Encryption
Toggle encryption at runtime:Data Message Encryption
With E2EE enabled, data messages are automatically encrypted:Monitoring Encryption State
ImplementRoomDelegate to monitor encryption state changes:
Encryption Types
The SDK supports different encryption types:Best Practices
Key Distribution
Key Distribution
- Never transmit keys through the LiveKit server
- Use a secure out-of-band channel for key distribution
- Consider using a key management service
- Rotate keys periodically for forward secrecy
Key Storage
Key Storage
- Store keys securely using iOS Keychain or similar
- Never hardcode keys in your application
- Clear keys from memory when no longer needed
Error Handling
Error Handling
- Monitor E2EE state changes via delegate
- Handle missing key scenarios gracefully
- Implement retry logic for transient failures
- Log encryption errors for debugging
Performance
Performance
- E2EE adds minimal latency (~1-2ms)
- CPU usage increases slightly for encryption/decryption
- No impact on network bandwidth
- Test on target devices to measure impact
Troubleshooting
Decryption Failures
If participants can’t decrypt media:- Verify all participants use the same shared key
- Check that E2EE manager is set up before connecting
- Ensure key index matches across participants
- Monitor E2EE state changes for specific errors
Missing Keys
If you seemissingKey state:
Legacy E2EEOptions
For backward compatibility, you can useE2EEOptions:
See Also
- E2EE/E2EEManager.swift
- E2EE/KeyProvider.swift