简体   繁体   English

Mifare身份验证

[英]Mifare authentication

Say I want to authenticate to Mifare Classic. 说我想要对Mifare Classic进行身份验证。

How do I know the exact kind of APDU to send to the card? 我如何知道要发送到卡的确切类型的APDU?

Example. 例。

This code: 这段代码:

bcla = 0xFF;
bins = 0x86;
bp1 =  0x0;
bp2 =  0x0; // currentBlock
len =  0x5;

sendBuffer[0] = bcla;
sendBuffer[1] = bins;
sendBuffer[2] = bp1;
sendBuffer[3] = bp2;
sendBuffer[4] = len;
sendBuffer[5] = 0x1;                // Version
sendBuffer[6] = 0x0;                // Address MSB
sendBuffer[7] = currentBlock;
if(keyradioButton->Checked==true)   // Address LSB
     sendBuffer[8] = 0x60;              // Key Type A
else if(keynumberradioButton->Checked ==true)
    sendBuffer[8] = 0x61;               // Key Type B
sendBuffer[9] = keynumber;          // Key Number

sendbufferlen = 0xA;
receivebufferlen = 255;

//Invoke the Transmit command
retval = SCardTransmit(hCard,  // A reference value returned from the SCardConnect function.
                                 &sioreq, 
                              sendBuffer,  // Send buffer
                           sendbufferlen,  // Send buffer length
                                 &rioreq, 
                           receiveBuffer,  // Receive butter
                      &receivebufferlen);  // Length of received buffer

is a sample program which tries to authenticate to Mifare Classic. 是一个示例程序,它尝试向Mifare Classic进行身份验证。 My question is basically, how do I know what kind of APDU to send to the card? 我的问题基本上是,如何知道发送给卡的APDU类型? eg, how do I know what should be in the sendBuffer ? 例如,我怎么知道sendBuffer应该sendBuffer什么?

In Mifare Classic 1K tags There are 16 Sectors and each Sectors contains 4 Blocks and each block contains 16 bytes. 在Mifare Classic 1K标签中有16个扇区,每个扇区包含4个块,每个块包含16个字节。

  1. Sector 0 contains Block (0,1,2,3) 扇区0包含块(0,1,2,3)
  2. Sector 1 contains Block (4,5,6,7) 第1区包含区块(4,5,6,7)
  3. Sector 2 contains Block (8,9,10,11) 第2区包含Block(8,9,10,11)
  4. Sector 3 contains Block (12,13,14,15).... 第3区包含Block(12,13,14,15)....

Before Reading or writing from a block You must have to Authenticate its corresponding Sector using Key A or Key B of that sector. 在从块读取或写入之前必须使用该扇区的密钥A或密钥B对其对应的扇区进行身份验证。 When Authentication is complete then you can read or write. 身份验证完成后,您可以读取或写入。 using this command you can authenticate sector 0 using KEY A(60) 使用此命令可以使用KEY A(60)验证扇区0

byte[] authenticationByte = new byte[10];  

authenticationByte = new byte[] { (byte) 0xFF, (byte) 0x86, (byte) 0x00,
 (byte) 0x00, (byte) 0x05, (byte) 0x00,(byte) 0x00, (byte) 0x04, 
                                    (byte) 0x60,(byte) 0x00 };

When Authentication is succes then you will get 90 00. That is Success message. 验证成功后,您将获得90 00.这是成功消息。 Else response is 63 00 , that means authentication failed. 否则响应是63 00,这意味着身份验证失败。 When Authentication complete then you can read block (0,1,2,3) cause sector 0 contains 4 block and those are block (0,1,2,3). 验证完成后,您可以读取块(0,1,2,3),因为扇区0包含4个块,那些是块(0,1,2,3)。

For more details you can read this Answer . 有关详细信息,请阅读此答案 Sorry for bad English 抱歉英语不好

阅读这篇文章。在这里你会发现APDU结构与Mifare卡进行通信......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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