コード例 #1
0
        public bool WriteBlockRange(byte msb, byte blockFrom, byte blockTo, byte[] data)
        {
            isoReaderInit();
            card = new MifareCard(isoReader);

            byte i;
            var  count     = 0;
            var  blockData = new byte[16];

            for (i = blockFrom; i <= blockTo; i++)
            {
                if ((i + 1) % 4 == 0)
                {
                    continue;
                }

                Array.Copy(data, count * 16, blockData, 0, 16);

                if (WriteBlock(msb, i, blockData))
                {
                    count++;
                }
                else
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #2
0
        public bool ClearAllBlock()
        {
            //var res = false;

            isoReaderInit();
            card = new MifareCard(isoReader);

            var data = new byte[16];

            if (card.LoadKey(KeyStructure.VolatileMemory, 0x00, key))
            {
                for (byte i = 1; i <= 63; i++)
                {
                    if ((i + 1) % 4 == 0)
                    {
                    }
                    else
                    {
                        if (card.Authenticate(Msb, i, KeyType.KeyA, 0x00))
                        {
                            Array.Clear(data, 0, 16);
                            if (WriteBlock(Msb, i, data))
                            {
                            }
                            else
                            {
                                return(false);
                            }
                        }
                    }
                }
            }

            return(true);
        }
コード例 #3
0
        public byte[] ReadBlockRange(byte msb, byte blockFrom, byte blockTo)
        {
            isoReaderInit();
            card = new MifareCard(isoReader);

            byte i;
            var  nBlock = 0;
            var  count  = 0;

            for (i = blockFrom; i <= blockTo; i++)
            {
                if ((i + 1) % 4 == 0)
                {
                    continue;
                }
                nBlock++;
            }

            var dataOut = new byte[nBlock * 16];

            for (i = blockFrom; i <= blockTo; i++)
            {
                if ((i + 1) % 4 == 0)
                {
                    continue;
                }
                Array.Copy(ReadBlock(msb, i), 0, dataOut, count * 16, 16);
                count++;
            }

            return(dataOut);
        }
コード例 #4
0
        public SmartCardOperation()
        {
            var ctx = contextFactory.Establish(SCardScope.System);

            readerNames = ctx.GetReaders();

            card = new MifareCard(isoReader);
        }
コード例 #5
0
        public byte[] ReadBlock(byte msb, byte lsb)
        {
            isoReaderInit();
            card = new MifareCard(isoReader);

            var readBinary = new byte[16];

            if (card.LoadKey(KeyStructure.VolatileMemory, 0x00, key))
            {
                if (card.Authenticate(msb, lsb, KeyType.KeyA, 0x00))
                {
                    readBinary = card.ReadBinary(msb, lsb, 16);
                }
            }

            return(readBinary);
        }
コード例 #6
0
        public bool IsReaderAvailable()
        {
            if (NoReaderAvailable(readerNames))
            {
                return(false);
            }

            nfcReader = readerNames[0];
            if (string.IsNullOrEmpty(nfcReader))
            {
                return(false);
            }

            isoReaderInit();
            card = new MifareCard(isoReader);

            return(true);
        }
コード例 #7
0
        public void isoReaderInit()
        {
            try
            {
                var ctx = contextFactory.Establish(SCardScope.System);
                isoReader = new IsoReader(
                    ctx,
                    nfcReader,
                    SCardShareMode.Shared,
                    SCardProtocol.Any,
                    false);

                card = new MifareCard(isoReader);
            }
            catch (Exception)
            {
                //MessageBox.Show(ex.Message, "Info", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }
コード例 #8
0
        public bool WriteBlock(byte msb, byte lsb, byte[] data)
        {
            isoReaderInit();
            card = new MifareCard(isoReader);

            if (card.LoadKey(KeyStructure.VolatileMemory, 0x00, key))
            {
                if (card.Authenticate(msb, lsb, KeyType.KeyA, 0x00))
                {
                    if (card.UpdateBinary(msb, lsb, data))
                    {
                        return(true);
                    }
                }

                return(false);
            }

            return(false);
        }