asyncEncrypt function

Future asyncEncrypt(
  1. String? prvKey,
  2. String? psw, [
  3. Map<String, dynamic>? options
])

Implementation

Future<dynamic> asyncEncrypt(String? prvKey, String? psw,
    [Map<String, dynamic>? options]) async {
  final response = new ReceivePort();

  await Isolate.spawn(
    _isolate_encrypt,
    response.sendPort,
    onExit: response.sendPort,
  );

  final sendPort = await response.first as SendPort;
  final receivePort = new ReceivePort();

  sendPort.send([prvKey, psw, options, receivePort.sendPort]);

  try {
    final result = await receivePort.first;
    var resultString = result.toString();

    if (resultString.startsWith('@@LaksaError@@')) {
      throw resultString.substring(14);
    }
    response.close();
    return result;
  } catch (e) {
    rethrow;
  }
}