/**
         *
         * Método que faz a validação de senha
         * para leitura e escrita de um bloco no SETOR A
         *
         * @param bloco  = Número do bloco que será validado a permissão
         *
         * @throws IOException
         *
         * @return boolean = Caso falso é porque não existe a permissão para leitura do bloco
         *
         * */
        private bool ValidPermissaoBlocoA(int bloco)
        {
            bool retorno = false;

            try
            {
                if (mifareClassic.AuthenticateSectorWithKeyA(bloco, (byte[])MifareClassic.KeyMifareApplicationDirectory))
                {
                    retorno = true;
                }
                else if (mifareClassic.AuthenticateSectorWithKeyA(bloco, (byte[])MifareClassic.KeyDefault))
                {
                    retorno = true;
                }
                else if (mifareClassic.AuthenticateSectorWithKeyA(bloco, (byte[])MifareClassic.KeyNfcForum))
                {
                    retorno = true;
                }
                else
                {
                    retorno = false;
                }
            }
            catch (IOException e)
            {
                throw new System.Exception(e.Message);
            }

            return(retorno);
        }
示例#2
0
        public NFCMessage MifareClassic_AuthenticateSectorWithKeyA(MifareClassic mfc, int Sector, List <byte[]> Keys)
        {
            if (mfc == null)
            {
                return(NFCMessage.NFC_NULL_MIFARECLASSIC);
            }
            if (!mfc.IsConnected)
            {
                mfc.Connect();
            }
            bool auth = false;
            int  i    = 0;

            if (Keys == null || Keys.Count == 0)
            {
                auth = mfc.AuthenticateSectorWithKeyA(Sector, MifareClassic.KeyNfcForum.ToArray());
                if (!auth)
                {
                    auth = mfc.AuthenticateSectorWithKeyA(Sector, MifareClassic.KeyDefault.ToArray());
                }
            }
            else
            {
                while (!auth || i != Keys.Count)
                {
                    auth = mfc.AuthenticateSectorWithKeyA(Sector, Keys[i]);
                    i++;
                }
            }
            return(auth ? NFCMessage.NFC_AUTH_OK : NFCMessage.NFC_AUTH_FAIELD);
        }
示例#3
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));
            }
        }