Exemplo n.º 1
0
        public byte[] ReadByteBlock(int block, byte[] key, NfcKeyType nfcKeyType)
        {
            //TODO 4. MIFARE OPERATIONS 2
            try
            {
                //No card found
                if (!LoadCurrentMifareClassic())
                {
                    return(null);
                }

                //Different card ids
                if (!CheckCardId())
                {
                    return(null);
                }

                //No authenticated
                if (!AuthenticateSector(block, nfcKeyType, key))
                {
                    return(null);
                }

                byte[] data = currentMifareClassic.ReadBlock(block);
                return(data);
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        private bool AuthenticateSector(int block, NfcKeyType nfcKeyType, byte[] key)
        {
            int sector = currentMifareClassic.BlockToSector(block);

            switch (nfcKeyType)
            {
            case NfcKeyType.KeyB:
                return(key != null && currentMifareClassic.AuthenticateSectorWithKeyB(sector, key));

            case NfcKeyType.KeyA:
            default:
                return(key != null && currentMifareClassic.AuthenticateSectorWithKeyA(sector, key));
            }
        }
Exemplo n.º 3
0
        public bool WriteByteBlock(int block, byte[] key, byte[] content, NfcKeyType nfcKeyType)
        {
            //TODO 4. MIFARE OPERATIONS 3
            try
            {
                if (content?.Length != 16)
                {
                    return(false);
                }

                //No card found
                if (!LoadCurrentMifareClassic())
                {
                    return(false);
                }

                //Different card ids
                if (!CheckCardId())
                {
                    return(false);
                }

                //No authenticated
                if (!AuthenticateSector(block, nfcKeyType, key))
                {
                    return(false);
                }

                currentMifareClassic.WriteBlock(block, content);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 4
0
 public bool WriteByteBlock(int block, byte[] key, byte[] content, NfcKeyType nfcKeyType)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 5
0
 public byte[] ReadByteBlock(int block, byte[] key, NfcKeyType nfcKeyType)
 {
     throw new NotImplementedException();
 }