sharedSecretKey method

  1. @override
Future<SecretKey> sharedSecretKey({
  1. required KeyPair keyPair,
  2. required PublicKey remotePublicKey,
})
override

Calculates a shared SecretKey.

Example

In this example, we use X25519:

import 'package:cryptography/cryptography.dart';

Future<void> main() async {
  final algorithm = X25519();

  // We need the private key pair of Alice.
  final aliceKeyPair = await algorithm.newKeyPair();

  // We need only public key of Bob.
  final bobKeyPair = await algorithm.newKeyPair();
  final bobPublicKey = await bobKeyPair.extractPublicKey();

  // We can now calculate a 32-byte shared secret key.
  final sharedSecretKey = await algorithm.sharedSecretKey(
    keyPair: aliceKeyPair,
    remotePublicKey: bobPublicKey,
  );
}

Implementation

@override
Future<SecretKey> sharedSecretKey({
  required KeyPair keyPair,
  required PublicKey remotePublicKey,
}) {
  return fallback.sharedSecretKey(
    keyPair: keyPair,
    remotePublicKey: remotePublicKey,
  );
}