Encryption API for Unreal SDK

icon

Usage in Blueprints and C++


PubNub Unreal SDK provides built-in message encryption to secure your real-time communications. 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:

  1. Cryptors (IPubnubCryptorInterface), which are individual encryption algorithms (AES, Legacy)
  2. Provider interface (UPubnubCryptoModule), which is the top-level interface used by PubNub subsystem.
  3. Crypto module (IPubnubCryptoProviderInterface), which manages multiple cryptors with automatic algorithm selection.

To configure the cryptoModule to encrypt all messages, you can use the following methods in the Unreal SDK:

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

PubnubSubsystem->SetCryptoModule(CryptoModule)
* required
ParameterDescription
CryptoModule *
Type: TScriptInterface<IPubnubCryptoProviderInterface>
The crypto module object that implements IPubnubCryptoProviderInterface.

Sample code

To set crypto module and configure AES encryption/decryption for all messages:

Actor.h

Actor.cpp

Get crypto module

PubnubSubsystem->GetCryptoModule()

Returns

Returns the crypto module object that implements IPubnubCryptoProviderInterface which was set using SetCryptoModule(). If no crypto module was set, returns an empty interface.

Sample code

To get the crypto module:

Actor.h

Actor.cpp

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.

FeatureDescription
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.

FeatureDescription
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

Actor.cpp

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);
* required
ParameterDescription
CryptoModule *
Type: UObject*
The crypto module object that implements IPubnubCryptoProviderInterface.
Message *
Type: FString
The plaintext data to encrypt.

Sample code

Actor.h


Actor.cpp


Other examples

Encrypt using a module set during configuration

Actor.h

Actor.cpp

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);
* required
ParameterDescription
CryptoModule *
Type: UObject*
The crypto module object that implements IPubnubCryptoProviderInterface.
EncryptedMessage *
Type: FString
The Base64-encoded encrypted data to decrypt.

Sample code

Actor.h


Actor.cpp


Other examples

Decrypt using a module set during configuration

Actor.h

Actor.cpp

Returns

Returns the decrypted message as a plaintext FString or an empty string if decryption fails.

Complete example

Reference code
Set up your Unreal project and follow the instructions in the lines marked with ACTION REQUIRED before running the code.

ASample_CryptoFull.h


ASample_CryptoFull.cpp


Last updated on