Secure channel encryption
Media stream encryption ensures that only the authorized users in a channel can see and hear each other. This ensures that potential eavesdroppers cannot access sensitive and private information shared in a channel. While not every use case requires media stream encryption, Video Calling provides built-in encryption methods that guarantee data confidentiality during transmission.
This page shows you how to integrate built-in media stream encryption into your app using Video Calling.
Understand the tech
To ensure secure communication, your app uses the same SSL key and salt to encrypt and decrypt data in the channel. You use the key and salt to create an encryption configuration. Agora SD-RTN™ uses the encryption configuration to encrypt a stream and sends it to remote users. When the remote user receives the encrypted media stream, the remote app decrypts the media stream using the same salt and key.
The following figure shows the call flow for the media stream encryption:

All users in a channel must use the same encryption configuration to initiate agoraEngine and enable encryption before joining a channel. If you don’t have the correct configuration, you cannot decrypt channel content. Best practice is that your authentication system generates a new key and salt regularly.
Prerequisites
To follow this procedure you must have:
-
Implemented the SDK quickstart project for Video Calling.
-
OpenSSL latest version
Project setup
To encrypt the media streams in your app, you need to:
-
Open the SDK quickstart Video Calling project you created previously.
-
Set up OpenSSL in your development device.
Implement Agora media stream encryption
To implement media stream encryption, do the following:
-
Add the required imports
In
/app/java/com.example.<projectname>/MainActivity, add the following imports after the last import statement:Base64 requires that you set the
Min SDK Versionproperty in your project to26or higher. -
Add the required variables
In
/app/java/com.example.<projectname>/MainActivity, add the following declarations toMainActivityclass: -
Add the media stream encryption method
To enable media stream encryption in your app, create an
EncryptionConfigobject and specify a key, salt, and encryption mode. CallenableEncryptionand pass theEncryptionConfigobject as a parameter.In
/app/java/com.example.<projectname>/MainActivity, add the following method toMainActivityclass: -
Start encryption before joining a channel
In
/app/java/com.example.<projectname>/MainActivity, add the following code at the end ofSetupVideoSDKEngine:
Test your implementation
To ensure that you have implemented Agora media stream encryption in your app:
-
Add the 32-byte key to your app
-
Run the following command in a terminal window:
-
Paste the key returned into the
encryptionKeyvariable.
-
-
Add the 64-byte salt to your app
-
Run the following command in a terminal window:
-
Paste the salt returned into the
encryptionSaltBase64variable.
-
-
Generate a token in Agora Console.
-
In Android Studio, in
app/java/com.example.\<projectname>/MainActivity, updateappId,channelNameandtokenwith the values for your temporary token. -
Connect a physical Android device to your development machine.
-
In Android Studio, click Run app. You see the app running on your device.
If this is the first time you run your app, grant microphone and camera access.
-
Copy and install the
apkfor your app on a second Android test device.
- Press Join on both Android devices to join the same channel.
You see the local and remote videos on the two devices.
Communication between your test devices is end-to-end encrypted. This prevents data from being read or secretly modified by anyone other than the true sender and recipient.
Reference
This section contains information that completes the information in this page, or points you to documentation that explains other aspects to this product.