decrypt method

Future decrypt(
  1. dynamic data, {
  2. String? timeKey,
})

Implementation

Future<dynamic> decrypt(dynamic data, {String? timeKey}) async {
  _setTime(timeKey);
  // File or media decryption
  if (data is String && await File(data).exists()) {
    final file = File(data);
    final buf = await file.readAsBytes();
    if (buf.isEmpty || buf.length < 2) {
      throw ArgumentError('File is too small or corrupted for decryption.');
    }
    final extLen = buf[0];
    final ext = utf8.decode(buf.sublist(1, 1 + extLen));
    final encData = buf.sublist(1 + extLen);
    final decBytes = _proc(encData, false);
    final base = data.substring(0, data.length - '.kaalka'.length);
    final outfile = base + ext;
    await File(outfile).writeAsBytes(decBytes);
    return outfile;
  }
  // Text decryption
  if (data is String) {
    return _decryptMessage(data);
  }
  // Binary decryption
  if (data is List<int>) {
    return utf8.decode(_proc(data, false));
  }
  throw ArgumentError('Unsupported data type for decryption.');
}