deriveKey method

Key deriveKey({
  1. required KeyAlgorithm encryptionAlgorithm,
  2. required Key ephemeralKey,
  3. required Key recipientKey,
  4. required bool receive,
})

Derives an ECDH-ES shared key for anonymous encryption.

Throws an AskarKeyException if key derivation fails.

Implementation

Key deriveKey({
  required KeyAlgorithm encryptionAlgorithm,
  required Key ephemeralKey,
  required Key recipientKey,
  required bool receive,
}) {
  try {
    return Key(
      askarKeyDeriveEcdhEs(
        encryptionAlgorithm,
        ephemeralKey.handle,
        recipientKey.handle,
        algId,
        apu,
        apv,
        receive,
      ).getValueOrException(),
    );
  } catch (e) {
    throw AskarKeyException('Failed to derive key: $e');
  }
}