logo
Video Call
On this page

Audio and Video Stream Encryption

2024-01-02

Feature Overview

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.

Example Source Code Download

Please refer to Download Example Source Code to get the source code.

For related source code, please check the files in the "/ZegoExpressExample/Others/src/main/java/im/zego/others/security" directory.

Prerequisites

Before using the audio and video stream encryption feature, please ensure:

Usage Steps

1 Set publishing stream encryption key

Call the setPublishStreamEncryptionKey interface to set the encryption key for publishing streams. This interface takes effect whether called before or after publishing stream. The encryption key is set by the developer, and only lengths of 16/24/32 bytes are supported. 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 effective when publishing streams to the ZEGOCLOUD 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 decryption key on the playing stream side first, then update the encryption key on the publishing stream side.
  • If the encryption key on the publishing stream side is updated first and then the decryption key on the playing stream side is updated, the playing stream side may not be able to decrypt some frames, resulting in failure to play the stream. If the decryption key on the playing stream side is updated 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 lengths of 16/24/32 bytes are supported.
// The encryption key is set by the developer.
engine.setPublishStreamEncryptionKey(key);

2 Set playing stream decryption key

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

Warning
  • This interface is only effective when playing streams from the ZEGOCLOUD 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 decryption key on the playing stream side first, then update the encryption key on the publishing stream side.
  • Calling stopPlayingStream or logoutRoom will clear the decryption key.
// playStreamID is the playing stream ID
// key is the decryption key, only lengths of 16/24/32 bytes are supported.
engine.setPlayStreamDecryptionKey(playStreamID,key);

3 Start publishing/playing streams

Please refer to Quick Start - Implementation to complete "publishing stream" and "playing stream" related operations in order.

Previous

Geofencing

Next

Game Voice

On this page

Back to top