/// <summary>
        /// Save sector
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void BtnOkClick(object sender, EventArgs e)
        {
            byte[]     AccessBits;
            byte[]     SectorTrailer;
            byte[]     KeyA;
            byte[]     KeyB;
            CardBuffer cardbufA;
            CardBuffer cardbufB;

            if (!MemoryCardMifareClassic.Sector.isKeyValid(cbKeyA.Text))
            {
                MessageBox.Show(this, "Key A: please supply a valid 6-byte value, in hexadecimal (12 hex digits).", "Invalid entry", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                this.DialogResult = DialogResult.None;
                return;
            }

            if (!MemoryCardMifareClassic.Sector.isKeyValid(cbKeyB.Text))
            {
                MessageBox.Show(this, "Key B: please supply a valid 6-byte value, in hexadecimal (12 hex digits).", "Invalid entry", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                this.DialogResult = DialogResult.None;
                return;
            }

            AccessBits = computeSectorTrailer();
            if ((AccessBits == null) || (AccessBits.Length != 4))
            {
                MessageBox.Show(this, "Failed to compute the access bits.", "Internal error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.DialogResult = DialogResult.Cancel;
                return;
            }

            SectorTrailer = new byte[16];

            cardbufA = new CardBuffer(cbKeyA.Text);
            cardbufB = new CardBuffer(cbKeyB.Text);
            KeyA     = cardbufA.GetBytes();
            KeyB     = cardbufB.GetBytes();

            Array.ConstrainedCopy(KeyA, 0, SectorTrailer, 0, KeyA.Length);
            Array.ConstrainedCopy(AccessBits, 0, SectorTrailer, KeyA.Length, AccessBits.Length);
            Array.ConstrainedCopy(KeyB, 0, SectorTrailer, KeyA.Length + AccessBits.Length, KeyB.Length);

            // Save keyA and keyB
            Settings.RememberKeyA(cbKeyA.Text);
            Settings.RememberKeyB(cbKeyB.Text);

            if (!sector.setKeyA(KeyA) || !sector.setKeyB(KeyB))
            {
                MessageBox.Show(this, "Failed to define the new keys.", "Internal error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.DialogResult = DialogResult.Cancel;
                return;
            }
            this.DialogResult = DialogResult.OK;
        }
        void BtOkClick(object sender, EventArgs e)
        {
            if (cbKeyA.Text.Equals("") && cbKeyB.Text.Equals(""))
            {
                MessageBox.Show(this, "Both Keys can't be null", "Invalid entry", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.DialogResult = DialogResult.None;
                return;
            }

            if (!cbKeyA.Text.Equals(""))
            {
                if (!MemoryCardMifareClassic.Sector.isKeyValid(cbKeyA.Text, 6))
                {
                    MessageBox.Show(this, "Key A: please enter a 6-byte key, in hexadecimal (12 hex digits).", "Invalid entry", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    this.DialogResult = DialogResult.None;
                    return;
                }
                sectorControl.setKeyA(cbKeyA.Text);
                Settings.RememberReadKeys(cbKeyA.Text);
                Settings.RememberWriteKeys(cbKeyA.Text);
            }


            if (!cbKeyB.Text.Equals(""))
            {
                if (!MemoryCardMifareClassic.Sector.isKeyValid(cbKeyB.Text, 6))
                {
                    MessageBox.Show(this, "Key B: please enter a 6-byte key, in hexadecimal (12 hex digits).", "Invalid entry", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    this.DialogResult = DialogResult.None;
                    return;
                }
                sectorControl.setKeyB(cbKeyB.Text);
                Settings.RememberReadKeys(cbKeyB.Text);
                Settings.RememberWriteKeys(cbKeyB.Text);
            }
        }