PqForgeSecureSession class final

Encrypts and decrypts application payloads into self-describing AEAD wire packets, with an explicit choice of cipher suite and backend engine.

final session = PqForgeSecureSession(
  secretKey: derivedHybridKey,                       // 32 bytes
  cipherSuite: PqForgeCipherSuite.chaCha20Poly1305,
  engineProvider: PqForgeEngineProvider.pureDart,    // or .nativeCryptography
);

final packet = await session.encrypt(payload, associatedData: header);
final clear  = await session.decrypt(packet, associatedData: header);
session.dispose(); // wipe the key when finished

Wire format

Every packet is a single contiguous byte array:

+-----------------------------+------------------------------------+
|      Nonce / IV (12 B)      |      Ciphertext + Tag (variable)   |
+-----------------------------+------------------------------------+

encrypt uses a per-session nonce: 4 random bytes chosen at construction, then a 64-bit counter (SP 800-38D §8.2.1). The 12-byte nonce is prepended and the AEAD ciphertext-and-tag follows. One session cannot repeat a nonce. Two sessions that share a key stay distinct until their 32-bit salts collide. decrypt slices the leading PqForgeCipherSuite.nonceLength bytes back off as the nonce before authenticating the remainder. Because both engines emit the identical ciphertext || tag layout, a packet produced by one PqForgeEngineProvider decrypts cleanly under the other.

Constructors

PqForgeSecureSession({required Uint8List secretKey, required PqForgeCipherSuite cipherSuite, PqForgeEngineProvider engineProvider = PqForgeEngineProvider.pureDart})
Creates a session bound to secretKey, a cipherSuite, and an engineProvider (defaults to PqForgeEngineProvider.pureDart).

Properties

cipherSuite → PqForgeCipherSuite
The negotiated AEAD cipher suite.
final
engineProvider → PqForgeEngineProvider
The backend performing the AEAD computation.
final
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

decrypt(Uint8List packet, {Uint8List? associatedData}) → Future<Uint8List>
Decrypts a wire packet produced by encrypt (from either backend).
dispose() → void
Zeroizes the session's internal copy of the secret key.
encrypt(Uint8List payload, {Uint8List? associatedData}) → Future<Uint8List>
Encrypts payload into a nonce || ciphertext || tag wire packet.
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