End-to-End Encryption Key Provider - React Native
End-to-end encryption (E2EE) uses a key provider that you register with the SDK. Create a BaseKeyProvider, give it a shared key, and register it with setKeyProvider() before you join.
The key provider applies to the whole app, not to one RoomProvider.
Example
import React, { useEffect, useState } from "react";
import {
BaseKeyProvider,
RoomProvider,
setKeyProvider,
} from "@videosdk.live/react-native-sdk";
function EncryptedRoom() {
const [ready, setReady] = useState(false);
useEffect(() => {
const provider = new BaseKeyProvider();
provider.setSharedKey("YOUR-SECURE-KEY");
setKeyProvider(provider).then(() => setReady(true));
}, []);
if (!ready) return null;
return (
<RoomProvider
config={{ roomId: "room-id", participantName: "Test User" }}
token="your-token"
>
<RoomView />
</RoomProvider>
);
}
note
- Set the shared key, then register the provider, before you join.
setKeyProvider()reads the provider's keys when you call it. - Every participant must use the same shared key.
- To turn E2EE off, call
removeKeyProvider(). - To check whether your media is encrypted, read
e2eeEnabledfromuseRoom().
BaseKeyProvider
new BaseKeyProvider()
- Type:
(discardFrameWhenCryptorNotReady?: boolean) => BaseKeyProvider - Creates a key provider with no keys.
discardFrameWhenCryptorNotReadyis accepted and stored. It has no effect on React Native.
sharedKey
- Type:
string | null - The shared key set with
setSharedKey(), ornull. Read-only.
participantKeys
- Type:
Map<string, string> - The per-participant keys set with
setParticipantKey(), by participant id. Read-only.
setSharedKey()
- Type:
(key: string) => void - Sets the key every participant in the room shares. It returns at once. Do not
awaitit. - While a shared key is set, per-participant keys are ignored.
- The key is used when you pass the provider to
setKeyProvider(), so set it first. - Throws
ERROR_INVALID_PARAMETER(3073) whenkeyis empty.
removeKey()
- Type:
(participantId: string) => Promise<void> - Removes the key set for one participant, the same as
setParticipantKey(participantId, null). This device stops decrypting that participant until a new key is set. - It takes effect in the room only when this provider is the one registered with
setKeyProvider(). On any other provider it only forgets the stored key.
const provider = getKeyProvider();
await provider?.removeKey("participant-id");
SDK functions
Import these from @videosdk.live/react-native-sdk.
setKeyProvider()
- Type:
(provider: BaseKeyProvider | null) => Promise<void> - Registers the key provider for the next join. Call it before
RoomProviderjoins. A provider set later does not encrypt the room already running. - A shared key covers the whole room. Without one, only the participants given a key with
setParticipantKey()are encrypted. - Pass
nullto turn E2EE off, the same asremoveKeyProvider(). - Rejects with
ERROR_INVALID_PARAMETER(3073) whenprovideris not aBaseKeyProvider.
removeKeyProvider()
- Type:
() => Promise<void> - Turns end-to-end encryption off and forgets the provider set with
setKeyProvider().
getKeyProvider()
- Type:
() => BaseKeyProvider | null - Returns the provider passed to
setKeyProvider(), ornull.
setParticipantKey()
- Type:
(participantId: string, key: string | null) => Promise<void> - Sets, rotates or removes the encryption key for one participant, also while you are in the room. Pass
nullto remove the key. - The key is used only when no shared key is set.
- The key is also saved in the registered provider, so a rejoin uses it again.
- Rejects with
ERROR_INVALID_PARAMETER(3073) when no provider was set withsetKeyProvider().
import { setParticipantKey } from "@videosdk.live/react-native-sdk";
await setParticipantKey("participant-id", "PARTICIPANT-KEY");
Got a Question? Ask us on discord

