XCrypto class

AES-256-CTR backed by the platform's hardware-accelerated crypto — Android javax.crypto (Conscrypt/BoringSSL → ARMv8 AES instructions), Apple CommonCrypto, Windows CNG (AES-ECB over the counter blocks → AES-NI) — with a transparent pure-Dart fallback (encryptChunk) where no native handler ships (web / linux / unit tests). The bytes are encrypted as if a single continuous CTR stream whose initial counter block is iv had already processed pos plaintext bytes; CTR is symmetric, so the same call also decrypts. Native and fallback are byte-for-byte identical — the cross-engine parity tests are the guard.

The point is to keep a large attachment's encryption (100MB+ video) off the UI isolate and fast: hardware AES runs on a native background thread, the fallback on a spawned isolate, and the Dart caller only awaits a Future.

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Properties

isSupported → bool
Whether a native handler ships on this platform. Web-safe (uses defaultTargetPlatform, never dart:io) and cheap — it does not touch the channel. Note this returns true under flutter test on a macOS/iOS host even though no plugin is registered there, so a call throws MissingPluginException — callers must treat that as a fallback signal, the same as any native error.
no setter

Static Methods

aesCtrBytes({required Uint8List key, required Uint8List iv, required int pos, required Uint8List data}) → Future<Uint8List?>
Bytes-in / bytes-out variant of aesCtrEncryptRange — encrypts data directly instead of reading from disk. Used by the cross-engine parity test; production uploads use the range form so the plaintext stays off the Dart heap.
aesCtrEncryptRange({required String path, required int pos, required int size, required Uint8List key, required Uint8List iv}) → Future<Uint8List>
Encrypts file[pos .. pos+size) and returns the ciphertext. The native side opens path, seeks to pos, reads size bytes, and encrypts them off the platform main thread — only the ciphertext crosses the channel, so a large attachment never copies its plaintext into the Dart heap.