init method

Future<void> init()

Implementation

Future<void> init() async {
  if (_isInitialized) {
    return;
  }

  Key key;

  const storage = FlutterSecureStorage();
  final base64Key = await storage.read(key: _secureStorageKey);
  if (base64Key != null) {
    key = Key.fromBase64(base64Key);
  } else {
    key = Key.fromSecureRandom(32);
    await storage.write(key: _secureStorageKey, value: key.base64);
  }

  _encrypter = Encrypter(AES(key, mode: AESMode.cbc));
  _isInitialized = true;
}