encrypt method

Uint8List encrypt(
  1. Uint8List message
)

Implementation

Uint8List encrypt(Uint8List message) {
  final ourKeyPair = Curve.generateKeyPair();
  final sharedSecret =
      Curve.calculateAgreement(_theirPublicKey, ourKeyPair.privateKey);
  final derivedSecret = HKDFv3().deriveSecrets(
      sharedSecret, Uint8List.fromList(utf8.encode(provision)), 64);
  final parts = ByteUtil.splitTwo(derivedSecret, 32, 32);

  final version = Uint8List.fromList([1]);
  final ciphertext = getCiphertext(parts[0], message);
  final mac = _getMac(parts[1], ByteUtil.combine([version, ciphertext]));
  final body = ByteUtil.combine([version, ciphertext, mac]);
  final envelope = ProvisionEnvelope(ourKeyPair.publicKey.serialize(), body);
  final result = jsonEncode(envelope);
  return Uint8List.fromList(utf8.encode(result));
}