encrypt static method

Uint8List encrypt(
  1. Uint8List plainBytes,
  2. Uint8List keyBytes, {
  3. bool compress = true,
  4. int compressionLevel = 3,
  5. int chunkSize = 256 * 1024,
  6. int cryptoWorkers = -1,
  7. int zstdWorkers = -1,
})

Encrypts bytes with AES‑256‑GCM and optional compression.

Implementation

static Uint8List encrypt(
  Uint8List plainBytes,
  Uint8List keyBytes, {
  bool compress = true,
  int compressionLevel = 3,
  int chunkSize = 256 * 1024,
  int cryptoWorkers = -1,
  int zstdWorkers = -1,
}) {
  _validateKeyLength(keyBytes, allowEmpty: false);
  if (chunkSize <= 0) {
    throw ArgumentError('chunkSize must be positive.');
  }

  final algo = compress ? _algoZstd : _algoNone;
  final baseIv = _randomBytes(_ivLength);
  for (var i = 8; i < _ivLength; i++) {
    baseIv[i] = 0;
  }

  final workers = _normalizeWorkers(cryptoWorkers);
  final zstd = _normalizeWorkers(zstdWorkers);

  return ShieldFfi.load().encrypt(
    plainBytes,
    keyBytes,
    compressionAlgo: algo,
    compressionLevel: compressionLevel,
    chunkSize: chunkSize,
    baseIv: baseIv,
    cryptoWorkers: workers,
    zstdWorkers: zstd,
  );
}