Utility Methods API for PubNub Dart SDK

The methods on this page are utility methods that don't fit into other categories.

Pause

Call the pause() method to force the SDK to stop all requests to PubNub server when there are active subscribe channels.

Method(s)

To pause() the data transmission you can use the following method(s) in Dart SDK.

pause()

This method doesn't take any arguments.

Basic Usage

subscription.pause()

Resume

Call the resume() method to force the SDK to try and reach out PubNub.

Method(s)

To resume() the data transmission you can use the following method(s) in Dart SDK.

resume()

Basic Usage

subscribtion.resume()

This method doesn't take any arguments.

Encrypt File

Encrypts file content in bytes format.

Deprecated

The cipherKey parameter in this method is deprecated. We recommend that you configure a seprate 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)

pubnub.files.encryptFile(
List<int> bytes,
{CipherKey? cipherKey,
Keyset? keyset,
String? using}
)
ParameterTypeRequiredDescription
bytesList<int>YesFile content in bytes.
cipherKeycipherKeyOptionalA cipherKey to override Keyset.cipherKey. For more information, refer to Configuration.
keysetKeysetOptionalOverride for the PubNub default keyset configuration.
usingStringOptionalKeyset name from the keysetStore to be used for this method call.

Basic Usage

// create cryptoModule
var cryptoModule = CryptoModule.aesCbcCryptoModule(CipherKey.fromUtf8('abcd'));

// encrypt file data NOTE: same method because it works at byte level
var encryptedFileData = cryptoModule.encrypt(fileData);

Returns

Byte List of encrypted data.

Decrypt File

Decrypts file content in bytes format.

Deprecated

The cipherKey parameter in this method is deprecated. We recommend that you configure a seprate 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)

pubnub.files.decryptFile(
List<int> bytes,
{CipherKey? cipherKey,
Keyset? keyset,
String? using})
ParameterTypeRequiredDescription
bytesList<int>YesFile content in bytes.
cipherKeycipherKeyOptionalA cipherKey to override Keyset.cipherKey. For more information, refer to Configuration.
keysetKeysetOptionalOverride for the PubNub default keyset configuration.
usingStringOptionalKeyset name from the keysetStore to be used for this method call.

Basic Usage

// create cryptoModule
var cryptoModule = CryptoModule.aesCbcCryptoModule(CipherKey.fromUtf8('abcd'));

// encrypt file data NOTE: same method because it works at byte level
var encryptedFileData = cryptoModule.encrypt(fileData);

// decrypt file data
var decryptedFileData = cryptoModule.decrypt(encryptedFileData);

// create file again from decrypted file bytes
File('decryptedFile.jpg').writeAsBytesSync(decryptedFileData);

Returns

Byte list of decrypted data.

Time

This function returns the current timetoken value from the PubNub network.

Algorithm constructing the timetoken
timetoken = (Unix epoch time in seconds) * 10000000

Example of creating a timetoken for a specific time and date:

08/19/2013 @ 9:20pm in UTC = 1376961606
timetoken = 1376961606 * 10000000
timetoken = 13769616060000000

Method(s)

To fetch Time you can use the following method(s) in Dart SDK:

time()

Basic Usage

var response = await pubnub.time();

Returns

The time() operation returns a Timetoken which contains the following operations:

MethodTypeDescription
valueintReturns an int representation of current timetoken.
Last updated on