encryptWithDerivedKey function

Future<EncryptionResult> encryptWithDerivedKey(
  1. {required EncryptionStrategy encryptionStrategy,
  2. DerivationStrategy keyDerivationStrategy = DerivationStrategy.pbkdf2Hmac,
  3. required String passphrase,
  4. required List<int> data}
)

Encrypts data with a key derived from passphrase using keyDerivationStrategy, data must be provided in bytes A EncryptionKey can be a symmetrical key or a key pair, which corresponds to AES or RSA EncryptionStrategy

Implementation

Future<EncryptionResult> encryptWithDerivedKey({
  required EncryptionStrategy encryptionStrategy,
  DerivationStrategy keyDerivationStrategy = DerivationStrategy.pbkdf2Hmac,
  required String passphrase,
  required List<int> data,
}) async {
  assert(encryptionStrategy != EncryptionStrategy.rsa4096,
      'Asymmetric key encryption does not support derived keys');
  final derivedKey =
      await deriveNewKeyFromString(passphrase, keyDerivationStrategy);
  final result = await _encrypt(
    data: data as Uint8List,
    encryptionStrategy: encryptionStrategy,
    key: derivedKey,
  )
    ..derivationArtefacts = derivedKey.derivationArtefacts;
  return result;
}