Encryption API for Unreal SDK
Synchronous API
Encryption methods (SetCryptoModule, GetCryptoModule) are synchronous only; there are no async variants. Configure the crypto module on each UPubnubClient when using the Client API. When using multiple clients, each client has its own crypto module.
PubNub Unreal SDK includes message encryption. This documentation covers crypto module configuration and utility methods for encrypting and decrypting messages using both legacy 128-bit and enhanced 256-bit AES-CBC encryption.
For general SDK configuration and initialization, refer to the Configuration page.
Configuration
The crypto system in Unreal SDK consists of three main components:
- Cryptors (
IPubnubCryptorInterface), which are individual encryption algorithms (AES, Legacy) - Provider interface (
UPubnubCryptoModule), which is the top-level interface used by each PubNub client. - Crypto module (
IPubnubCryptoProviderInterface), which manages multiple cryptors with automatic algorithm selection.
To configure the crypto module for a client so that all messages are encrypted, use SetCryptoModule and GetCryptoModule on the UPubnubClient instance. When using multiple clients, set the crypto module on each client that should use encryption.
Automatic message encryption/decryption
Once configured, the crypto module automatically handles encryption and decryption:
- All published messages are encrypted using the default cryptor
- Received messages and fetched history messages are automatically decrypted using the appropriate cryptor (determined by the 4-byte identifier in the message header)
Set crypto module
Sets the crypto module for this client. All messages published or received by this client will use this module for encryption and decryption.
1PubnubClient->SetCryptoModule(TScriptInterface<IPubnubCryptoProviderInterface> CryptoModule);
| Parameter | Description |
|---|---|
CryptoModule *Type: TScriptInterface<IPubnubCryptoProviderInterface> | The crypto module object that implements IPubnubCryptoProviderInterface. Use UPubnubCryptoModule for the default PubNub encryption implementation. |
Returns
This method does not return a value.
Sample code
To set the crypto module and configure AES encryption/decryption for all messages for this client:
Get crypto module
Returns the crypto module currently set for this client.
1TScriptInterface<IPubnubCryptoProviderInterface> CryptoModule = PubnubClient->GetCryptoModule();
Returns
| Type | Description |
|---|---|
TScriptInterface<IPubnubCryptoProviderInterface> | The crypto module previously set with SetCryptoModule() for this client. Returns an empty interface if none was set. |
Sample code
To get the crypto module for the current client:
Available cryptors
The Unreal SDK provides two built-in cryptor implementations:
AES cryptor (UPubnubAesCryptor)
Uses 256-bit AES-CBC encryption with PKCS#7 padding. This is the recommended cryptor for new applications.
| Feature | Description |
|---|---|
| Identifier | 'A', 'C', 'R', 'H' (4-byte header identifier) |
| Key management | Set cipher key using SetCipherKey(FString) |
| IV generation | Generates random 16-byte IV for each encryption |
| Compatibility | Compatible with PubNub AES encryption across all SDKs |
Legacy cryptor (UPubnubLegacyCryptor)
Provides compatibility with older PubNub encryption implementations while encrypting messages with the AES cryptor. Use the AES cryptor if you don't need to decrypt legacy messages.
Legacy cryptor usage
Useful when your Unreal SDK must be able to decrypt messages encrypted with the legacy PubNub encryption from other SDKs.
| Feature | Description |
|---|---|
| Identifier | {0, 0, 0, 0} (4-byte legacy identifier) |
| Key management | Set cipher key using SetCipherKey(FString) |
| IV options | Supports both random IV (default) and fixed IV modes |
| Compatibility | Compatible with legacy PubNub encryption |
Legacy configuration
To configure legacy decryption for all messages:
Actor.h
1
Actor.cpp
1
Custom cryptors
To use a custom cryptor, you need to implement the IPubnubCryptorInterface interface. For more information, refer to the Data security section.
Encrypt
This function allows you to encrypt data manually using the configured crypto module.
Method(s)
To encrypt data you can use the following method in the Unreal SDK:
IPubnubCryptoProviderInterface::Execute_ProviderEncrypt(CryptoModule, Message);
| Parameter | Description |
|---|---|
CryptoModule *Type: UObject* | The crypto module object that implements IPubnubCryptoProviderInterface. |
Message *Type: FString | The plaintext data to encrypt. |
Sample code
Actor.h
1
Actor.cpp
1
Other examples
Encrypt using a module set during configuration
Actor.h
1
Actor.cpp
1
Returns
Returns the encrypted message as a Base64-encoded FString or an empty string if encryption fails.
Decrypt
This function allows you to decrypt data manually using the configured crypto module.
Method(s)
To decrypt data you can use the following method in the Unreal SDK:
IPubnubCryptoProviderInterface::Execute_ProviderDecrypt(CryptoModule, EncryptedMessage);
| Parameter | Description |
|---|---|
CryptoModule *Type: UObject* | The crypto module object that implements IPubnubCryptoProviderInterface. |
EncryptedMessage *Type: FString | The Base64-encoded encrypted data to decrypt. |
Sample code
Actor.h
1
Actor.cpp
1
Other examples
Decrypt using a module set during configuration
Actor.h
1
Actor.cpp
1
Returns
Returns the decrypted message as a plaintext FString or an empty string if decryption fails.
Set crypto module (deprecated)
Deprecated
Use PubnubClient->SetCryptoModule() instead. Crypto configuration is per client when using the Client API.
1PubnubSubsystem->SetCryptoModule(TScriptInterface<IPubnubCryptoProviderInterface> CryptoModule);
| Parameter | Description |
|---|---|
CryptoModule *Type: TScriptInterface<IPubnubCryptoProviderInterface> | The crypto module object that implements IPubnubCryptoProviderInterface. |
Get crypto module (deprecated)
Deprecated
Use PubnubClient->GetCryptoModule() instead. Each client has its own crypto module when using the Client API.
1PubnubSubsystem->GetCryptoModule();
Returns
Returns the crypto module object that implements IPubnubCryptoProviderInterface which was set using SetCryptoModule() on the default client. If no crypto module was set, returns an empty interface.
Complete example
Reference code
ACTION REQUIRED before running the code.ASample_CryptoFull.h
1
ASample_CryptoFull.cpp
1