defaultChannelDecryptionHandler method

Map<String, dynamic> defaultChannelDecryptionHandler(
  1. String sharedSecret,
  2. Map data
)

Implementation

Map<String, dynamic> defaultChannelDecryptionHandler(
  String sharedSecret,
  Map data,
) {
  if (!data.containsKey("ciphertext") || !data.containsKey("nonce")) {
    throw Exception(
      "Unexpected format for encrypted event, expected object with `ciphertext` and `nonce` fields, got: $data",
    );
  }

  final ByteList cipherText = _decodeCipherText(data["ciphertext"]);

  final Uint8List nonce = base64Decode(data["nonce"]);

  final SecretBox secretBox = SecretBox(base64Decode(sharedSecret));
  final Uint8List decryptedData = secretBox.decrypt(cipherText, nonce: nonce);

  return jsonDecode(utf8.decode(decryptedData)) as Map<String, dynamic>;
}