Audio and Video Stream Encryption
Introduction
This feature can be used to encrypt stream information to protect communication security.
Developers can encrypt streams when publishing. For encrypted streams, when playing streams, developers need to provide a decryption key that matches the encryption key, otherwise the stream cannot be played successfully.
Download Sample Source Code
Please refer to Download Sample Source Code to obtain the source code.
For related source code, please check the files in the "/ZegoExpressExample/Examples/Others/Security" directory.
Prerequisites
Before using the audio and video stream encryption feature, ensure that:
- A project has been created in the ZEGOCLOUD Console, and valid AppID and AppSign have been obtained. For details, please refer to Console - Project Information.
- ZEGO Express SDK has been integrated into the project, and basic audio and video streaming functionality has been implemented. For details, please refer to Quick Start - Integration and Quick Start - Implementation Process.
Usage Steps
1 Set the stream publishing encryption key
Call the setPublishStreamEncryptionKey interface to set the encryption key for stream publishing. This interface takes effect whether called before or after publishing the stream. The encryption key is set by the developer, and the length only supports 16/24/32 bytes. When developers play encrypted streams, they need to provide a decryption key that matches the encryption key, otherwise the stream cannot be played successfully.
- This interface is only valid when publishing streams to the ZEGO Video Call server or Low-Latency Live Streaming server.
- Supports calling setPublishStreamEncryptionKey during stream publishing to update the encryption key. Note that the decryption key on the playing end needs to be updated first before updating the encryption key on the publishing end.
- If the encryption key on the publishing end is updated first and then the decryption key on the playing end is updated, some frames on the playing end may not be decrypted, resulting in stream playing failure. If the decryption key on the playing end is updated first, the SDK will store both the old and new decryption keys, which can achieve seamless switching.
- Calling stopPublishingStream or logoutRoom will clear the encryption key.
// key is the encryption key, length only supports 16/24/32 bytes.
engine->setPublishStreamEncryptionKey(key);2 Set the stream playing decryption key
Call the setPlayStreamDecryptionKey interface to set the decryption key for stream playing. This interface takes effect whether called before or after playing the stream.
- This interface is only valid when playing streams from the ZEGO Video Call server or Low-Latency Live Streaming server.
- Supports calling setPlayStreamDecryptionKey during stream playing to update the decryption key. Note that the decryption key on the playing end needs to be updated first before updating the encryption key on the publishing end.
- Calling stopPlayingStream or logoutRoom will clear the decryption key.
// playStreamID is the stream ID for playing
// key is the decryption key, length only supports 16/24/32 bytes.
engine->setPlayStreamDecryptionKey(playStreamID,key);3 Start publishing/playing streams
Please refer to Quick Start - Implementation Process to complete the operations related to "publishing streams" and "playing streams" in sequence.
