-
- All Implemented Interfaces:
-
io.getstream.video.android.core.e2ee.E2EEManager
public final class StreamEncryptionManager implements E2EEManager
The SDK's default E2EEManager, backed by WebRTC's framed AES-GCM encryption. Frames are encrypted before they leave the device and decrypted after they arrive, so the SFU forwards media it cannot read.
Typical use, matching the JavaScript and iOS SDKs:
StreamEncryptionManager.create(myUserId).onSuccess { e2ee -> e2ee.setSharedKey(keyIndex = 0, key = myKeyBytes) call.setE2EEManager(e2ee) call.join() }You own the instance you create: keep it for as long as you need to rotate keys, and call dispose when you are done with it. The SDK does not dispose managers it did not create, since the same manager is usually reused across rejoins and often across calls.
Instances are safe to use from any thread. Key changes take effect on the frames encrypted after they are applied.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classStreamEncryptionManager.Companion
-
Field Summary
Fields Modifier and Type Field Description private final StringuserIdprivate final E2EEAlgorithmalgorithm
-
Method Summary
Modifier and Type Method Description final StringgetUserId()final E2EEAlgorithmgetAlgorithm()Result<Unit>encrypt(RtpSender sender, String codec, E2EETrackType trackType)Called once per outgoing track, right after the publisher adds its transceiver. Result<Unit>decrypt(RtpReceiver receiver, String userId, E2EETrackType trackType)Called once per incoming track, when the subscriber learns which participant it belongs to. final UnitsetSharedKey(Integer keyIndex, ByteArray key)Sets the key used for every participant that has no per-user key, including your own outgoing media. final UnitsetKey(String userId, Integer keyIndex, ByteArray key)Sets the key for a single participant, which takes precedence over the shared key. final UnitremoveSharedKey(Integer keyIndex)Drops the shared key at keyIndex. final UnitremoveKey(String userId, Integer keyIndex)Drops userId's key at keyIndex, falling back to the shared key for that participant. final UnitremoveAllKeys(String userId)Drops every key held for userId, at every index, falling back to the shared key for that participant. final UnitsetEventListener(E2EEEventListener listener)Observes encryption state changes, most importantly decryption failures. final UnitenablePerformanceReporting(Boolean enabled)Turns on periodic E2EEEventType.PERF_REPORT events carrying per-track crypto timings. final UnitrequestKeyState()Asks for a E2EEEventType.KEY_STATE event describing the keys currently held. final Unitdispose()Releases the native manager and wipes its keys. -
-
Method Detail
-
getAlgorithm
final E2EEAlgorithm getAlgorithm()
-
encrypt
Result<Unit> encrypt(RtpSender sender, String codec, E2EETrackType trackType)
Called once per outgoing track, right after the publisher adds its transceiver. The implementation is expected to install a frame encryptor on sender.
- Parameters:
sender- The sender carrying the local track.codec- The negotiated codec, lowercased and without a MIME prefix (opus,vp8,av1), ornullwhen the SDK cannot determine it.trackType- Which kind of track this is, ornullwhen it cannot be mapped.
-
decrypt
Result<Unit> decrypt(RtpReceiver receiver, String userId, E2EETrackType trackType)
Called once per incoming track, when the subscriber learns which participant it belongs to. The implementation is expected to install a frame decryptor on receiver.
- Parameters:
receiver- The receiver carrying the remote track.userId- The user the track belongs to.trackType- Which kind of track this is, ornullwhen it cannot be mapped.
-
setSharedKey
final Unit setSharedKey(Integer keyIndex, ByteArray key)
Sets the key used for every participant that has no per-user key, including your own outgoing media. Use this when everyone in the call shares one passphrase-derived key.
Safe to call during a call to rotate keys: write the new key to the next index, and peers that still hold the old index can decode frames that were already in flight.
- Parameters:
keyIndex- Slot to write to.key- Raw key bytes, sized for algorithm — 16 bytes for AES-128-GCM, 32 for AES-256-GCM.
-
setKey
final Unit setKey(String userId, Integer keyIndex, ByteArray key)
Sets the key for a single participant, which takes precedence over the shared key. Use this when each participant publishes under their own key. See setSharedKey for rotation.
-
removeSharedKey
final Unit removeSharedKey(Integer keyIndex)
Drops the shared key at keyIndex.
-
removeAllKeys
final Unit removeAllKeys(String userId)
Drops every key held for userId, at every index, falling back to the shared key for that participant. Shared keys are untouched — use removeSharedKey for those.
-
setEventListener
final Unit setEventListener(E2EEEventListener listener)
Observes encryption state changes, most importantly decryption failures. Pass
nullto stop observing. The listener is invoked on a WebRTC internal thread, so hop to your own dispatcher before touching UI state.
-
enablePerformanceReporting
final Unit enablePerformanceReporting(Boolean enabled)
Turns on periodic E2EEEventType.PERF_REPORT events carrying per-track crypto timings. Off by default; it costs a timing measurement per frame, so leave it off outside diagnostics.
-
requestKeyState
final Unit requestKeyState()
Asks for a E2EEEventType.KEY_STATE event describing the keys currently held. Answered asynchronously through the listener registered with setEventListener, so register first.
-
dispose
final Unit dispose()
Releases the native manager and wipes its keys. Drops the setEventListener observer first so a listener that captured a ViewModel or Activity is not kept alive by native. Subsequent key operations are ignored; attempting to attach an encryptor or decryptor returns a failure so the SDK cannot treat an unprotected track as configured. Dispose only once you are done with every call that uses it.
-
-
-
-