deriveSymKey function

Future<String> deriveSymKey(
  1. String privateKeyA,
  2. String publicKeyB
)

Implementation

Future<String> deriveSymKey(String privateKeyA, String publicKeyB) async {
  final privateKeyBytes = hex.decode(privateKeyA);
  final publicKeyBytes = hex.decode(publicKeyB);
  // final sharedKey = await crypto.X25519().sharedSecretKey(
  //       keyPair: crypto.SimpleKeyPair(
  //         privateKeyBytes,
  //       ),
  //       remotePublicKey: remotePublicKey,
  //     );

  final sharedKey = curve.X25519(privateKeyBytes, publicKeyBytes);
  var okm = Uint8List(KEY_LENGTH);
  final hkdfX = HKDFKeyDerivator(SHA256Digest())
    ..init(pc.HkdfParameters(sharedKey, KEY_LENGTH));
  hkdfX.deriveKey(null, 0, okm, 0);

  // final hkdf = DartHkdf(
  //   hmac: DartHmac(DartSha256()),
  //   outputLength: KEY_LENGTH,
  // );

  // final symKey = await hkdf.deriveKey(
  //     secretKey: await crypto.SecretKeyData.random(length: 32).extract());
  // return hex.encode(await symKey.extractBytes());
  return hex.encode(okm);
}