Ejemplo n.º 1
0
        private void buttonGetMACReader_Click(object sender, EventArgs e)
        {
            string csnString = textBoxCSN.Text.Replace(" ", "");
            string keyString = textBoxKey.Text.Replace(" ", "");
            string ccString  = textBoxCC.Text.Replace(" ", "");
            string nrString  = textBoxNR.Text.Replace(" ", "");


            //import.ProcessData(1, 10, s => textBox1.Text = s);
            if (csnString.Length != 0 && csnString.Length != 16)
            {
                showInputLengthErrorMessage("16", "CNC");
                return;
            }
            if (keyString.Length != 0 && keyString.Length != 16)
            {
                showInputLengthErrorMessage("16", "KEY");
                return;
            }
            if (ccString.Length != 0 && ccString.Length != 16)
            {
                showInputLengthErrorMessage("16", "CC");
                return;
            }
            if (nrString.Length != 0 && nrString.Length != 8)
            {
                showInputLengthErrorMessage("8", "NR");
                return;
            }
            byte[] key = new byte[8] {
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
            };
            byte[] csn = new byte[8] {
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
            };
            byte[] ccNr = new byte[12] {
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
            };


            HexHelper.FillArrayFromString(csnString, ref csn);
            HexHelper.FillArrayFromString(keyString, ref key);
            HexHelper.FillArrayFromString(ccString, ref ccNr);
            HexHelper.FillArrayFromString(nrString, ref ccNr, 8);


            import.ComputeReaderMAC(key, csn, ccNr, s => printResult(s));
        }
Ejemplo n.º 2
0
        private void buttonGetCRC_Click(object sender, EventArgs e)
        {
            string mess;// = property + " length must be " + len;

            if (textBoxDataForCRC.Text.Length == 0)
            {
                mess = "Data for CRC can't be less than 1 byte";
                MessageBox.Show(mess, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if ((textBoxDataForCRC.Text.Length % 2) != 0)
            {
                mess = "Data for CRC must be even";
                MessageBox.Show(mess, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                byte[] data = new byte[(textBoxDataForCRC.Text.Length / 2)];
                //byte[] data = Encoding.ASCII.GetBytes(textBoxDataForCRC.Text);
                HexHelper.FillArrayFromString(textBoxDataForCRC.Text, ref data);
                import.ComputeCRC(data, data.Length, s => printResult(s));
            }
        }
Ejemplo n.º 3
0
        private void buttonGetMACTag_Click(object sender, EventArgs e)
        {
            string csnString = textBoxCSN.Text.Replace(" ", "");
            string keyString = textBoxKey.Text.Replace(" ", "");
            string ccString  = textBoxCC.Text.Replace(" ", "");
            string nrString  = textBoxNR.Text.Replace(" ", "");

            if (csnString.Length != 0 && csnString.Length != 16)
            {
                showInputLengthErrorMessage("16", "CNC");
                return;
            }
            if (keyString.Length != 0 && keyString.Length != 16)
            {
                showInputLengthErrorMessage("16", "KEY");
                return;
            }
            if (ccString.Length != 0 && ccString.Length != 16)
            {
                showInputLengthErrorMessage("16", "CC");
                return;
            }
            if (nrString.Length != 0 && nrString.Length != 8)
            {
                showInputLengthErrorMessage("8", "NR");
                return;
            }
            const int dataLength = 8 + 8 + 8 + 4;

            byte[] data = new byte[dataLength];

            HexHelper.FillArrayFromString(keyString, ref data);
            HexHelper.FillArrayFromString(csnString, ref data, 8);
            HexHelper.FillArrayFromString(ccString, ref data, 8 + 8);
            HexHelper.FillArrayFromString(nrString, ref data, 8 + 8 + 8);

            import.ComputeMAC(new byte[8], data, data.Length, 1, s => printResult(s));
        }