简体   繁体   English

Android Mifare Classic身份验证密钥A无法正常工作

[英]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 };
  • What does each byte in this key represent? 该密钥中的每个字节代表什么?
  • If I have a key like 3c5528125c61 as above, how should I write the byte array to authenticate, read block 2 and get the bytes? 如果我有一个像上述的3c5528125c61这样的密钥,我该如何写字节数组进行身份验证,读取块2并获取字节?
  • What is an AID (Application code)? 什么是AID(应用代码)? When should I use it? 我什么时候应该使用它?

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 };

How do I authenticate to a sector and read a data block? 如何验证扇区并读取数据块?

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之后可以读取),您可以执行以下操作:

  1. Authenticate to the sector that contains the block to read (block 2 is located in sector 0, you can use the helber method MifareClassic.blockToSector() to obtain the sector number for a given block number. 对包含要读取的块的扇区进行身份验证(块2位于扇区0中,可以使用helber方法MifareClassic.blockToSector()获得给定块号的扇区号。
  2. If authentication was successful, you can read the block. 如果身份验证成功,则可以读取该块。
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();

What is AID (Application Identifier)? 什么是AID(应用程序标识符)? and when should I use it? 什么时候应该使用它?

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM