Audio and Video Stream Encryption
Overview
This document does not apply to the Web platform.
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.
Demo Source Code Download
Please refer to Download Demo Source Code to obtain the source code.
For related source code, please check the files in the "lib/topics/OtherFunctions/security" directory.
Prerequisites
Before using the audio and video stream encryption feature, please ensure:
- You have integrated the ZEGO Express SDK into your project and implemented basic real-time audio and video functions. For details, please refer to Quick Start - Integration and Quick Start - Implementation.
- You have created a project in the ZEGOCLOUD Console and obtained a valid AppID and AppSign. For details, please refer to Console - Project Information.
Usage Steps
1 Set publishing stream encryption key
Call the setPublishStreamEncryptionKey interface to set the encryption key for publishing streams. This interface can take effect when called before or after publishing streams. The encryption key is set by the developer, and only supports lengths of 16/24/32 bytes. When playing encrypted streams, developers 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 ZEGO Video Call servers or Live Streaming servers.
- Supports calling setPublishStreamEncryptionKey during publishing to update the encryption key.
- You need to update the playing stream decryption key first before updating the publishing stream encryption key; if you update the publishing stream encryption key first and then update the playing stream decryption key, the playing end may not be able to decrypt some frames, resulting in playing stream failure. If you update the playing stream decryption key first, the SDK will store both the old and new decryption keys, achieving seamless switching.
- Calling stopPublishingStream or logoutRoom will clear the encryption key.
// key is the encryption key, only supports lengths of 16/24/32 bytes.
// The encryption key is set by the developer.
ZegoExpressEngine.instance.setPublishStreamEncryptionKey(key);2 Set playing stream decryption key
Call the setPlayStreamDecryptionKey interface to set the playing stream decryption key. This interface can take effect when called before or after playing streams.
- This interface is only valid when playing streams from ZEGO Video Call servers or Live Streaming servers.
- Supports calling setPlayStreamDecryptionKey during playing to update the decryption key. Note: You need to update the playing stream decryption key first before updating the publishing stream encryption key.
- Calling stopPlayingStream or logoutRoom will clear the decryption key.
// playStreamID is the playing stream ID
// key is the decryption key, only supports lengths of 16/24/32 bytes.
ZegoExpressEngine.instance.setPlayStreamDecryptionKey(playStreamID,key);3 Start publishing/playing streams
Please refer to Quick Start - Implementation to complete publishing and playing stream related operations in sequence.
