logo
Video Call
On this page

Audio and Video Stream Encryption

2024-01-02

Feature Introduction

This feature can be used to encrypt stream information to protect communication security.

Developers can encrypt streams when publishing. For already encrypted streams, when playing, developers need to provide a decryption key that matches the encryption key, otherwise the stream cannot be played successfully.

Sample Source Code Download

Please refer to Download Sample Source Code to get 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, please ensure:

Usage Steps

1 Set the publishing stream encryption key

Call the setPublishStreamEncryptionKey interface to set the encryption key for publishing. This interface takes effect whether called before or after publishing. The encryption key is set by the developer, and the length only supports 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.

Warning
  • This interface is only valid when publishing to the ZEGO Video Call server or Low Latency Live Streaming server.
  • Supports calling setPublishStreamEncryptionKey during publishing to update the encryption key. Note that you need to update the playing end decryption key first, then update the publishing end encryption key.
  • If you update the publishing end encryption key first and then update the playing end decryption key, the playing end may not be able to decrypt some frames, which will lead to playing failure. If you update the playing end decryption key first, the SDK will store both the old and new decryption keys and can achieve 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 sharedEngine]setPublishStreamEncryptionKey:self.publishKey];

2 Set the playing stream decryption key

Call the setPlayStreamDecryptionKey interface to set the playing stream decryption key. This interface takes effect whether called before or after playing.

Warning
  • This interface is only valid when playing from the ZEGO Video Call server or Low Latency Live Streaming server.
  • Supports calling setPlayStreamDecryptionKey during playing to update the decryption key. Note that you need to update the playing end decryption key first, then update the publishing end 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 sharedEngine]setPlayStreamDecryptionKey:self.playKey streamID:self.streamID];

3 Start publishing/playing streams

Please refer to Quick Start - Implementation Flow to complete the "publishing stream" and "playing stream" operations in sequence.

2024-01-02

Previous

Geofencing

Next

Game Voice

On this page

Back to top