[英]Android Mifare Classic authentication Key A not working
I'm having a problem in my application with the MifareClassic.autenticateSectorWithKeyA(int sector, byte[] keyA)
method. 我的
MifareClassic.autenticateSectorWithKeyA(int sector, byte[] keyA)
方法在我的应用程序中遇到问题。 I have tried many ways but it dose not authenticate. 我已经尝试了许多方法,但是它不能进行身份验证。
My key A is: 我的密钥A是:
byte[] key = new byte[] { (byte) 0x3c, (byte) 0x55, (byte) 0x28,
(byte) 0x12, (byte) 0x5c, (byte) 0x61, (byte) 0x00,
(byte) 0x5C, (byte) 0x71, (byte) 0x00 };
3c5528125c61
as above, how should I write the byte array to authenticate, read block 2 and get the bytes? 3c5528125c61
这样的密钥,我该如何写字节数组进行身份验证,读取块2并获取字节? Your key
byte array does not make much sense as a MIFARE Classic key. 您的
key
字节数组作为MIFARE Classic密钥没有多大意义。 A key for MIFARE Classic consists of only 6 bytes. MIFARE Classic的密钥只有6个字节。 Hence, this would be a possible value for key:
因此,这可能是key的可能值:
byte[] key = new byte[] { (byte)0x3c, (byte)0x55, (byte)0x28,
(byte)0x12, (byte)0x5c, (byte)0x61 };
In order to read block 2 (and assuming that it is readable after authenticationg with the above key
), you would do something like the following: 为了读取第2块(并假设在使用上面的
key
进行身份验证g之后可以读取),您可以执行以下操作:
MifareClassic.blockToSector()
to obtain the sector number for a given block number. MifareClassic.blockToSector()
获得给定块号的扇区号。 final MifareClassic mfc = MifareClassic.get(tag); mfc.connect(); final int blockNumber = 2; if (mfc.authenticateSectorWithKeyA(mfc.blockToSector(blockNumber), key)) { final byte[] data = mfc.readBlock(blockNumber) // TODO: do something with data } mfc.close();
MIFARE Classic itself has a linear memory layout. MIFARE Classic本身具有线性内存布局。 Ie one that is addressed based on block numbers, where each block contains 16 bytes.
即基于块号寻址的块,其中每个块包含16个字节。 These blocks are grouped into sectors with individual access conditions and keys.
这些块分为具有各自访问条件和密钥的扇区。
In order to logically assign this data (the sectors/groups of blocks) to specific applications (eg some data for a physical access control system, some data for an electronic purse, etc.) and, hence, to use one card for more that one application at the same time, the MIFARE Application Directory (MAD) was introduced. 为了逻辑上将此数据(块的扇区/组)分配给特定的应用程序(例如,一些用于物理访问控制系统的数据,一些用于电子钱包的数据等),因此,使用一张卡进行更多的分配同时引入了一个应用程序,即MIFARE应用程序目录(MAD)。 The MAD is basically a lookup table (located in sector 0 for MIFARE Classic 1K and in sectors 0 and 16 for MIFARE Classic 4K).
MAD基本上是一个查找表(对于MIFARE Classic 1K,位于扇区0中,对于MIFARE Classic 4K,位于扇区0和16中)。 This lookup table maps each sector of the card to one application.
该查找表将卡的每个扇区映射到一个应用程序。 Applications are identified though a two byte value, the MIFARE application identifier (AID).
通过两个字节的值(MIFARE应用程序标识符(AID))来标识应用程序。 Thus, if a card uses the MAD, an application can lookup its data sectors by browsing the MAD for its AID.
因此,如果卡使用MAD,则应用程序可以通过浏览MAD的AID来查找其数据扇区。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.