encrypt method

  1. @override
Future<String?> encrypt({
  1. required String tag,
  2. required String message,
  3. required String sharedPreferences,
})
override

Implementation

@override
Future<String?> encrypt({
  required String tag,
  required String message,
  required String sharedPreferences,
}) async {
  var iv = await getIV(key: tag, sharedPreferences: sharedPreferences);
  log('iv sp : $iv');

  final res = await methodChannel.invokeMethod<String?>(
    'encrypt',
    {
      'tag': tag,
      'message': message,
      'iv': iv,
    },
  );

  if (res == null) return null;
  var jsonRes = json.decode(res);
  if (iv == null) {
    log('iv new : ${jsonRes['iv']}');

    await setIV(
      key: tag,
      value: jsonRes['iv'],
      sharedPreferences: sharedPreferences,
    );
  }

  return jsonRes['ciphertext'];
}