initialize static method

void initialize({
  1. required String appSecret,
  2. required String appId,
})

Initializes the InternalSessionUtils with the provided appSecret and appId.

This method must be called before using any other methods of InternalSessionUtils. If an instance has already been initialized, an Exception will be thrown.

The appSecret is used to generate a 32-byte key for encryption. The appId is encoded used to generate a 16-byte initialization vector (IV).

Throws:

  • Exception if the instance is already initialized.

Example:

InternalSessionUtils.initialize(appSecret: 'yourAppSecret', appId: 'yourAppId');

Implementation

static void initialize({required String appSecret, required String appId}) {
  if (_instance != null) {
    return;
  }
  _registerProviders();
  final appKey = base64To32ByteKey(appSecret);
  final encrypter = Encrypter(AES(Key(appKey)));
  final base64AppId = base64Encode(utf8.encode(appId));
  final iv = IV(base64To16ByteKey(base64AppId));

  _instance = InternalSessionUtils._(encrypter, iv);
}