logo
Video Call
On this page

Audio and Video Stream Encryption

2024-01-02

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:

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.

Warning
  • 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.

Warning
  • 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.

Previous

Geofencing

Next

Game Voice

On this page

Back to top