encrypt static method
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,
);
}