Utility Methods API for Unity SDK
The methods on this page are utility methods that don't fit into other categories.
Cleanup
Cleanup frees up the threads and allows for clean exit.
Method(s)
Pubnub.CleanUp()
Basic Usage
Reference code
This example is a self-contained code snippet ready to be run. It includes necessary imports and executes methods with console logging. Use it as a reference when working with other examples in this document.
using PubnubApi;
using PubnubApi.Unity;
using UnityEngine;
public class PubnubCleanupExample : MonoBehaviour {
// Reference to a pubnub manager previously setup in Unity Editor
// For more details, see https://www.pubnub.com/docs/sdks/unity#configure-pubnub
[SerializeField] private PNManagerBehaviour pubnubManager;
private void OnApplicationQuit() {
// Getting a reference to the Pubnub instance
var pubnub = pubnubManager.pubnub;
// Performing cleanup operations
Debug.Log("Cleaning up PubNub resources...");
show all 19 linesReturns
None
Encrypt
This function allows to encrypt
the data.
Deprecated
The cipherKey
parameter in this method is deprecated. We recommend that you configure a separate instance of the crypto module and use it for partial encryption.
If you pass cipherKey
as an argument, it overrides the crypto module configuration and the legacy encryption with 128-bit cipher key entropy is used.
Method(s)
To encrypt
the data you can use the following method(s) in Unity SDK.
pubnub.Encrypt(inputString, cipherKey)
Parameter | Description |
---|---|
inputString *Type: String | The data to encrypt . |
cipherKey Type: String | Cipher key to use for encryption. |
Basic Usage
Encrypt part of message
string stringToEncrypt = "hello world";
var crypto = PubnubApi.Security.Crypto.CryptoModule.CreateAesCbcCryptor("test");
crypto.Encrypt(stringToEncrypt);
Encrypt File
This function allow to encrypt
the file content/data.
Deprecated
The cipherKey
parameter in this method is deprecated. We recommend that you configure a separate instance of the crypto module and use it for partial encryption.
If you pass cipherKey
as an argument, it overrides the crypto module configuration and the legacy encryption with 128-bit cipher key entropy is used.
Method(s)
To encrypt
the file you can use the following method(s) in Unity SDK.
pubnub.EncryptFile(sourceFile, destinationFile, cipherKey)
Parameter | Description |
---|---|
sourceFile *Type: String | File to be encrypted. |
destinationFile *Type: String | Path of the encrypted file to be saved. |
cipherKey Type: String | Cipher Key to use for encryption. If provided, the legacy encryption with 128-bit cipher key entropy is used. If not provided, the CryptoModule from PubNub config will be used. For more information, refer to Crypto module configuration. |
byte[] outputBytes = pubnub.EncryptFile(sourceBytes) byte[] outputBytes = pubnub.EncryptFile(sourceBytes, cipherKey)
Parameter | Description |
---|---|
sourceBytes *Type: byte[] | byte array of the file. |
cipherKey Type: String | Cipher Key to use for encryption. If provided, the legacy encryption with 128-bit cipher key entropy is used. If not provided, the CryptoModule from PubNub config will be used. For more information, refer to Crypto module configuration. |
Basic Usage
string source_file = "cat_picture.jpg"; // checks bin folder if no path is provided
string destination_file = "destination_cat_pic.jpg"; // checks bin folder if no path is provided
var crypto = PubnubApi.Security.Crypto.CryptoModule.CreateAesCbcCryptor("test");
crypto.EncryptFile(source_file, destination_file);
byte[] sourceBytes = System.IO.File.ReadAllBytes("cat_picture.jpg"); // checks bin folder if no path is provided
var crypto = PubnubApi.Security.Crypto.CryptoModule.CreateAesCbcCryptor("test");
byte[] outputBytes = crypto.EncryptFile(sourceBytes);
System.IO.File.WriteAllBytes("destination_cat_pic.jpg", outputBytes); // checks bin folder if no path is provided
Decrypt
This function allows to decrypt
the data.
Deprecated
The cipherKey
parameter in this method is deprecated. We recommend that you configure a separate instance of the crypto module and use it for partial encryption.
If you pass cipherKey
as an argument, it overrides the crypto module configuration and the legacy encryption with 128-bit cipher key entropy is used.
Method(s)
To decrypt
the data you can use the following method(s) in Unity SDK.
pubnub.Decrypt(inputString, cipherKey)
Parameter | Description |
---|---|
inputString *Type: String | The data to decrypt . |
cipherKey Type: String | Cipher key used for decryption. |
Basic Usage
Decrypt part of message
string encryptedString = "9qR0Q4TuDUwiLTcxtIY3mA==";
string cipherKey = "testCipher";
string decryptedMessage = pubnub.Decrypt(encryptedString, cipherKey);
Decrypt File
This function allow to decrypt
the file content/data.
Deprecated
The cipherKey
parameter in this method is deprecated. We recommend that you configure a separate instance of the crypto module and use it for partial encryption.
If you pass cipherKey
as an argument, it overrides the crypto module configuration and the legacy encryption with 128-bit cipher key entropy is used.
Method(s)
To decrypt
the file you can use the following method(s) in Unity SDK.
pubnub.DecryptFile(sourceFile, destinationFile, cipherKey);
Parameter | Description |
---|---|
sourceFile *Type: String | File to be decrypted. |
destinationFile *Type: String | Path of the decrypted file to be saved. |
cipherKey Type: String | Cipher Key to use for decryption. If provided, the legacy encryption with 128-bit cipher key entropy is used. If not provided, the CryptoModule from PubNub config will be used. For more information, refer to Crypto module configuration. |
byte[] outputBytes = pubnub.DecryptFile(sourceBytes) byte[] outputBytes = pubnub.DecryptFile(sourceBytes, cipherKey)
Parameter | Description |
---|---|
sourceBytes *Type: byte[] | byte array of the file. |
cipherKey Type: String | Cipher Key to use for decryption. If provided, the legacy encryption with 128-bit cipher key entropy is used. If not provided, the CryptoModule from PubNub config will be used. For more information, refer to Crypto module configuration. |
Basic Usage
string source_file = "encrypted_cat_pic.jpg"; // checks bin folder if no path is provided
string destination_file = "cat_pic_original.jpg"; // checks bin folder if no path is provided
var crypto = PubnubApi.Security.Crypto.CryptoModule.CreateAesCbcCryptor("test");
crypto.DecryptFile(source_file, destination_file);
byte[] sourceBytes = System.IO.File.ReadAllBytes("encrypted_cat_pic.jpg"); // checks bin folder if no path is provided
var crypto = PubnubApi.Security.Crypto.CryptoModule.CreateAesCbcCryptor("test");
byte[] outputBytes = crypto.DecryptFile(sourceBytes);
System.IO.File.WriteAllBytes("cat_pic_original.jpg", outputBytes); // checks bin folder if no path is provided
Disconnect
Call the Disconnect
method to force the SDK to stop all requests to PubNub server when there are active subscribe channels.
Method(s)
To disconnect
the data transmission you can use the following method(s) in Unity SDK.
Disconnect<T>()
This method doesn't take any arguments.
Basic Usage
pubnub.Disconnect<string>();