SecureBytes class
Wrapper for sensitive byte data with automatic zeroing on finalization.
Important limitations:
- Dart GC may copy data before finalizer runs
- This is defence-in-depth, not a security guarantee
- For maximum security, call dispose explicitly when done
Thread/Isolate safety:
This class is designed for single-isolate use. The _disposed flag is not
atomic, but this is not a practical concern because Dart isolates don't share
memory. Each isolate should have its own SecureBytes instances.
Usage:
// Copy constructor - original data is NOT zeroed (caller responsible)
final secure = SecureBytes(sensitiveBytes);
// Wrap constructor - takes ownership, original reference should not be used
final secure = SecureBytes.wrap(sensitiveBytes);
// ... use secure.bytes ...
secure.dispose(); // Explicit zeroing (recommended)
Constructors
- SecureBytes(Uint8List data)
- Creates a SecureBytes by copying the input data.
-
SecureBytes.fromList(List<
int> data) - Creates SecureBytes from a list of integers (copies data).
- SecureBytes.wrap(Uint8List data)
-
Creates a SecureBytes by taking ownership of the input data.
factory
Properties
- bytes → Uint8List
-
Access the underlying bytes.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- isDisposed → bool
-
Whether this instance has been disposed.
no setter
- length → int
-
The length of the data (0 if disposed).
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
dispose(
) → void - Explicitly zero and dispose the data.
-
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