private async void nfcService_MessageReceivedCompleted(ProximityMessage message) { switch (message.MessageType) { case NFC_IBCS: { PeerFinder.TriggeredConnectionStateChanged += TriggeredConnectionStateChanged; PeerFinder.Start(); nfcService.UnsubscribeForMessage(NFC_IBCS); break; } case NFC_IBCS_ACK: { nfcService.UnsubscribeForMessage(NFC_IBCS_ACK); identity = message.DataAsString; nfcService.PublishTextMessage(NFC_IBCS_ACK, (string)settingsService.Get("email")); aes.GenerateKey(); ct = await bfService.CipherMessage(aes.Key, message.DataAsString, (SerializedPrivateKey)settingsService.Get("private")); nfcService.PublishTextMessage(NFC_IBCS_KEY, ct); break; } case NFC_IBCS_KEY: { byte[] pt = await bfService.DecipherMessage(message.DataAsString, (SerializedPrivateKey)settingsService.Get("private")); byte[] newKey = BFUtil.Xor(aes.Key, pt); aes.Key = newKey; nfcService.UnsubscribeForMessage(NFC_IBCS_KEY); if (NfcPairingCompleted != null) { NfcPairingCompleted(); } break; } } }