Data encryption
Data encryption ensures that only the authorized users in a channel communicate with each other. This ensures that potential eavesdroppers cannot access sensitive and private information shared in a channel. While not every use case requires data encryption, Signaling provides built-in encryption methods that guarantee data confidentiality during transmission.
This page shows you how to integrate built-in data encryption into your app using Signaling.
Understand the tech
The following figure shows the call flow for the data 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.
Signaling provides security for user applications in the following ways:
- Transport layer encryption: for data transmission between your app and Agora SD-RTN™.
- Message encryption: each message is protected with end-to-end AES_256_GCM encryption protection.
- Token authorization - time-based access access control strategy.
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 data stream, the remote app decrypts the data stream using the same salt and key.
If your app must be highly secure, or meet security compliance standards like HIPAA or SOC 2 type 2, use message-level encryption. For a higher levels combine TLS encryption with end-to-end AES encryption.
Prerequisites
To follow this page, you must have:
- Setup the Signaling SDK reference app.
- Installed the latest version of OpenSSL
Implement Agora data stream encryption
To implement data 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 Version
property in your project to26
or higher. -
Add the required variables
In
/app/java/com.example.<projectname>/MainActivity
, add the following declarations toMainActivity
class: -
Add the media stream encryption method
To enable media stream encryption in your app, create an
EncryptionConfig
object and specify a key, salt, and encryption mode. CallenableEncryption
and pass theEncryptionConfig
object as a parameter.In
/app/java/com.example.<projectname>/MainActivity
, add the following method toMainActivity
class: -
Start encryption before joining a channel
In
/app/java/com.example.<projectname>/MainActivity
, add the following code at the end ofSetupVideoSDKEngine
:
Test data encryption
To test this functionality:
-
Create the cypher key and salt
-
Create the 32-byte key with the following command:
-
Create the 64-byte salt with the following command
-
-
Configure data encryption
In
<samples-root>/src/signaling_manager/config.json
:-
Paste the
-hex 32 key
into thecipherKey
variable. -
Paste the salt from the
-base64 32
call into thesalt
variable. -
Set
encryptionMode
to 1.
-
-
Set the APP ID
In
agora-manager/res/raw/config.json
, setappId
to the AppID of your project. -
Set the authentication method
Choose one of the following authentication methods:
- Temporary token:
- Set
rtcToken
with the value of your temporary token. - Set
channelName
- with the name of a channel you used to create the token.
- Set
- Authentication server:
- Setup an Authentication server
- In
config.json
, set:channelName
with the name of a channel you want to join.rtcToken
to an empty string.serverUrl
to the base URL of your authentication server. For example,https://agora-token-service-production-1234.up.railway.app
.
- Temporary token:
-
Start the Android reference app
-
In Android Studio, connect a physical Android device to your development machine.
-
Click Run to start the app.
A moment later you see the project installed on your device. If this is the first time you run the project, you need to grant microphone and camera access to your app.
-
-
Test data encryption
Login to Signaling as multiple users, then send and receive secure messages.
-
In Android Studio, in
app/java/com.example.\<projectname>/MainActivity
, updateappId
,channelName
andtoken
with 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
apk
for 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.