First of all, MIFARE Classic cards do not use APDU commands. Therefore, you are not sending APDUs to the card, but to the card reader (which translates them into MIFARE Classic commands). The APDU commands to be processed by the reader usually begin with an FF class byte.
In MIFARE Classic cards, the keys (A and B) and access conditions for each sector are stored in the sector trailer (the last block of each sector). The MIFARE Classic 1K card has 16 sectors with 4 blocks each.
So, if you want to set the keys and access conditions for sector 0, you will need to write them to block 3 (the last block of sector 0). The PC / SC standard defines a write command (UPDATE BINARY) for memory cards as:
FF D6 XXYY 10 ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
Where XXYY is the address of the block, and ZZ... is the data that should be written to the block.
Sector trailer format (see this answer for more details ):
<key A> | access bits | general purpose byte | <key B>
So, to install
- key A =
00 11 22 33 44 55 - key B =
66 77 88 99 AA BB - access bits =
787788 (the sector trailer is writable only using key B; access bits / GPB can be read using keys A or B; data blocks are written only using key B; data blocks can be read using key A or B) - GPB set to
69
for sector 0, you should use the following write command:
FF D6 0003 10 001122334455 787788 69 66778899AABB
Please note that you cannot partially update the sector trailer; you always need to create and record a trailer for the entire sector.
source share