问题描述
Mifare Classic 1K的程序是
The procedure of Mifare Classic 1K is
- 轮询标签
- 验证这些标签
- 如果验证成功则读/写。
我已经完成了这些程序并且还阅读了从特定部门写入数据。
I already completed those procedures and also read and write data from specific sectors.
轮询标签的命令是
new byte[] { (byte) 0xFF, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x04, (byte) 0xD4, (byte) 0x4A,
(byte) 0x01, (byte) 0x00 }
验证命令是
new byte[] { (byte) 0xFF, (byte) 0x86, (byte) 0x00,
(byte) 0x00, (byte) 0x05, (byte) 0x01,(byte) 0x00, (byte) 0x04,
(byte) 0x60,(byte) 0x00 };
这里(字节)0x01是Sector 1
Here "(byte) 0x01" is the Sector 1
写入第1区,第5区
new byte[] { (byte) 0xFF, (byte) 0x00, (byte) 0x00,(byte) 0x00, (byte) 0x15, (byte) 0xD4,
(byte) 0x40,(byte) 0x01, (byte) 0xA0, (byte) 0x05,(byte) 0x01, (byte) 0x02,
(byte) 0x03,(byte) 0x04, (byte) 0x05, (byte) 0x06, (byte) 0x07,(byte) 0x08,
(byte) 0x09,(byte) 0x0A,(byte) 0x0B, (byte) 0x0C, (byte) 0x0D,(byte) 0x0E,
(byte) 0x0F, (byte) 0x10};
此处
(byte) 0x01, (byte) 0x02, (byte) 0x03,(byte) 0x04, (byte) 0x05, (byte) 0x06, (byte) 0x07,(byte) 0x08,(byte) 0x09,(byte) 0x0A,(byte) 0x0B, (byte) 0x0C, (byte) 0x0D,(byte) 0x0E,(byte) 0x0F,(byte) 0x10
是第1区第5区写的数据。
is data those are writing on block 5 on Sector 1.
从第1区和第5区读取命令是
new byte[] { (byte) 0xFF, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x05, (byte) 0xD4, (byte) 0x40,
(byte) 0x01, (byte) 0x30, (byte) 0x05 };
我的问题是如何锁定/只读特定扇区的块?
My Problem is how can I "Lock/make read only" a block from a specific sector?
推荐答案
MIFARE卡每个扇区的验证密钥和访问条件位于该扇区的最后一个块中(部门预告片)。您可以使用常规写入命令使用新访问条件和身份验证密钥更新此块。
The authentication keys and the access conditions for each sector of a MIFARE card are located in the last block of that sector (the sector trailer). You can update this block with new access conditions and authentication keys using a regular write command.
扇区预告片如下所示:
+-----------------------------+--------------+----+-----------------------------+
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
+-----------------------------+--------------+----+-----------------------------+
| Key A | Access Bits | GP | Key B |
| (6 bytes) | (3 bytes) | B | (6 bytes) |
+-----------------------------+--------------+----+-----------------------------+
因此访问位位于字节6-8中,如下所示:
So the access bits are located in byte 6-8 and look like this:
+-------+-------+-------+-------+-------+-------+-------+-------+
| Bit 0 | Bit 1 | Bit 2 | Bit 3 | Bit 4 | Bit 5 | Bit 6 | Bit 7 |
+-------+-------+-------+-------+-------+-------+-------+-------+
Byte 6: | nC2_3 | nC2_2 | nC2_1 | nC2_0 | nC1_3 | nC1_2 | nC1_1 | nC1_0 |
+-------+-------+-------+-------+-------+-------+-------+-------+
Byte 7: | C1_3 | C1_2 | C1_1 | C1_0 | nC3_3 | nC3_2 | nC3_1 | nC3_0 |
+-------+-------+-------+-------+-------+-------+-------+-------+
Byte 8: | C3_3 | C3_2 | C3_1 | C3_0 | C2_3 | C2_2 | C2_1 | C2_0 |
+-------+-------+-------+-------+-------+-------+-------+-------+
其中nCx_y =不是Cx_y,C1_x,C2_x,C3_x是块x的访问条件:
Where nCx_y = not Cx_y and "C1_x, C2_x, C3_x" is the access condition for block x:
- C1_3,C2_3,C3_3:扇区预告片(该部门的第3块)
- C1_2,C2_2,C3_2:该部门的第2块
- C1_1,C2_1,C3_1:该部门的第1块
- C1_0,C2_0,C3_0:此部门中的第0块
- C1_3, C2_3, C3_3: sector trailer (block 3 in this sector)
- C1_2, C2_2, C3_2: block 2 in this sector
- C1_1, C2_1, C3_1: block 1 in this sector
- C1_0, C2_0, C3_0: block 0 in this sector
您可以找到详细信息MIFARE 1K数据表中可能的访问条件列表:
You can find a detailed list of possible access conditions in the MIFARE 1K datasheet: http://www.nxp.com/documents/data_sheet/MF1S503x.pdf
这篇关于Mifare Classic 1K的锁定机制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!