encryptWithKeyAndArtefacts method

  1. @override
Future<EncryptionResult> encryptWithKeyAndArtefacts(
  1. List<int> data,
  2. EncryptionKey key,
  3. EncryptionArtefacts artefacts
)
override

Allows encryption with specified encryption artifacts (rather than generated ones).

Implementation

@override
Future<EncryptionResult> encryptWithKeyAndArtefacts(
    List<int> data, EncryptionKey key, EncryptionArtefacts artefacts) async {
  final encrypted = await _cipher.encrypt(data,
      secretKey: SecretKey((key as SymmetricKey).bytes),
      nonce: artefacts.nonce,
      aad: artefacts.authData);

  final cipherText = encrypted.cipherText;
  final authTag = encrypted.mac.bytes;

  artefacts.authTag = authTag;

  return EncryptionResult.fromComponents(
      strategy: _strategy,
      cipherText: cipherText,
      encryptionArtefacts: artefacts);
}