newMacSink method

  1. @override
Future<DartMacSinkMixin> newMacSink({
  1. required SecretKey secretKey,
  2. List<int> nonce = const <int>[],
  3. List<int> aad = const <int>[],
})
override

Constructs a sink for calculating a Mac.

The parameter secretKey must be non-empty.

The parameter nonce can be const <int>[].

The parameter aad is Associated Authenticated Data (AAD). It can be empty. If it's non-empty and the algorithm does not support AAD, the the method throws ArgumentError.

Example

import 'package:cryptography_plus/cryptography_plus.dart';

void main() {
  final secretKey = SecretKey([1,2,3]);

  // Create a sink
  final sink = await Hmac.sha256().newMacSink(
    secretKey: secretKey,
  );

  // Add chunks of data
  sink.add([4,5,6]);
  sink.add([7,8]);

  // Close
  sink.close();

  // We now have a MAC
  final mac = await sink.mac();

  print('MAC: ${mac.bytes');
}

Implementation

@override
Future<DartMacSinkMixin> newMacSink({
  required SecretKey secretKey,
  List<int> nonce = const <int>[],
  List<int> aad = const <int>[],
}) async {
  final secretKeyData = await secretKey.extract();
  return newMacSinkSync(
    secretKeyData: secretKeyData,
    nonce: nonce,
    aad: aad,
  );
}