logo
Video Call
On this page

Security Encryption

2023-11-21

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, developers need to provide a decryption key that matches the encryption key, otherwise the stream cannot be successfully played.

Download Example Source Code

Please refer to Download Example 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 security encryption feature, ensure that:

Usage Steps

1 Set Publishing Stream Encryption Key

Call setPublishStreamEncryptionKey to set the publishing stream encryption key. This interface can be called before or after publishing the stream.

Warning
  • This interface is only valid when publishing to the Zego RTC server.

  • It supports calling setPublishStreamEncryptionKey during publishing to update the encryption key. Note that the playing stream's decryption key must be updated first before updating the publishing stream's encryption key, otherwise the stream playing will fail.

  • Calling stopPublishingStream or logoutRoom will clear the encryption key.

// key is the encryption key, only supports lengths of 16/24/32 bytes.
engine->setPublishStreamEncryptionKey(key);

2 Set Playing Stream Decryption Key

Call setPlayStreamDecryptionKey to set the playing stream decryption key. This interface can be called before or after playing the stream.

Warning
  • This interface is only valid when playing from the Zego RTC or L3 server.
  • It supports calling setPlayStreamDecryptionKey during playing to update the decryption key. Note that the playing stream's decryption key must be updated first before updating the publishing stream's encryption key, otherwise the stream playing will fail.
  • Calling stopPlayingStream or logoutRoom will clear the encryption key.
// playStreamID is the playing stream ID
// key is the decryption key, only supports lengths of 16/24/32 bytes.
engine->setPlayStreamDecryptionKey(playStreamID,key);

Start Publishing and Playing Streams

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

API Reference List

MethodDescription
setPublishStreamEncryptionKeySet publishing stream encryption key
setPlayStreamDecryptionKeySet playing stream decryption key

Previous

Geofencing

Next

Game Voice

On this page

Back to top