initialize method

  1. @override
Future<void> initialize({
  1. required bool isEncrypting,
  2. required SecretKey secretKey,
  3. required List<int> nonce,
  4. List<int> aad = const [],
  5. int keyStreamIndex = 0,
})
override

Initializes the state with the given secretKey, nonce, and aad.

Implementation

@override
Future<void> initialize({
  required bool isEncrypting,
  required SecretKey secretKey,
  required List<int> nonce,
  List<int> aad = const [],
  int keyStreamIndex = 0,
}) async {
  _isInitialized = false;
  _isEncrypting = isEncrypting;
  this.keyStreamIndex = keyStreamIndex;
  final secretKeyData = await secretKey.extract();
  final derivedSecretKey = deriveKeySync(
    secretKey: secretKeyData,
    nonce: nonce,
  );
  final derivedNonce = deriveNonce(
    secretKey: secretKeyData,
    nonce: nonce,
  );
  final macSink = await cipher.macAlgorithm.newMacSink(
    secretKey: secretKey,
    nonce: nonce,
    aad: aad,
  );
  _macSink = macSink;
  assert(!_isInitialized);
  _isInitialized = true;
  beforeData(
    secretKey: derivedSecretKey,
    nonce: derivedNonce,
    aad: aad,
  );
}