private void WriteDataToTag(Tag tag)
        {
            try
            {
                ndefHandler.SetKeys(AppSettings.Global.PubKey, AppSettings.Global.PrivKey);
                ndefHandler.SetExtraSignDataFromTag(tag);

                byte[]      rawNdefMsg = ndefHandler.GenerateRawNdefMessage(writeData);
                NdefMessage ndefMsg    = new NdefMessage(rawNdefMsg);

                bool?written = WriteNdef(tag, ndefMsg);

                if (written == false)
                {
                    written = FormatNdef(tag, ndefMsg);
                }

                if (written == true)
                {
                    ShowToast("Written " + ndefMsg.ByteArrayLength + " bytes of NDEF data.");
                    Finish();
                }
            }
            finally
            {
                ndefHandler.ClearKeys();
                ndefHandler.ClearExtraSignData();
            }
        }
Esempio n. 2
0
        private byte[] ProcessUpdate(byte[] apdu)
        {
            int address = ((apdu[2] & 0xFF) << 8) | (apdu[3] & 0xFF);

            if (address < 0 || address >= 1024)
            {
                return(WRONG_PARAMETERS);
            }

            if (address != 0)
            {
                return(WRONG_PARAMETERS);
            }

            int length = apdu[4] & 0xFF;

            if (apdu.Length < length + 5)
            {
                return(STATUS_FAILED);
            }

            if (dataToPublish == null || confirmed)
            {
                return(FILE_NOT_FOUND);
            }

            byte[] challenge = new byte[length];
            Buffer.BlockCopy(apdu, 5, challenge, 0, length);

            try
            {
                ndefHandler.SetKeys(AppSettings.Global.PubKey, AppSettings.Global.PrivKey);
                ndefHandler.SetExtraSignData(challenge);
                ndefHandler.KeepEmptyFields = true;

                ndefData = ndefHandler.GenerateRawNdefMessage(dataToPublish);

                return(STATUS_SUCCESS);
            }
            catch (Exception e)
            {
                ShowToast("Failed preparing HCE data: " + e.Message);
                return(STATUS_FAILED);
            }
            finally
            {
                ndefHandler.ClearKeys();
                ndefHandler.ClearExtraSignData();
            }
        }