logo
On this page

Audio and Video Stream Encryption

2024-01-02

Overview

Caution

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:

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.

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

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

Previous

Geofencing

Next

Game Voice

On this page

Back to top