I have got two type of Mifare Classic tags. One have UID of 4 byte and other one have 7 byte. I am trying to read the block of both. I am successful in reading the block of the tag having 4 byte UID but failed to authenticate in case of 7 byte UID. The reader I am using is a ACR122U and reading using ACR122U Tool.
Assuming you are using an older version of the ACR122U, you would use the PN532 data exchange command to send an authentication command:
FF 00 0000 0F D440 <TAG_ID> <AUTH_TYPE> <BLOCK> <KEY> <UID>
<TAG_ID>
is the index of the tag on the reader (typically 0x01). <AUTH_TYPE>
is 0x60 if you want to authenticate with key A and 0x61 if you want to authenticate with key B. <BLOCK>
is the block to authenticate for. <KEY>
is the 6-byte key (e.g. FF FF FF FF FF FF
for the default key). <UID>
is the 4-byte UID (or the last 4 bytes of a 7-byte UID).
So if you want to authenticate using key A A0 A1 A2 A3 A4 A5
for block 0 on a tag with the UID 04 AA BB CC DD EE FF
, you would use the following command:
FF 00 0000 0F D440 01 60 00 A0A1A2A3A4A5 CCDDEEFF
On newer versions of the reader, you would instead use the standardized mechanism for contactless memory cards defined by PC/SC:
Load authentication keys:
FF 82 0000 06 <KEY>
Authenticate:
FF 86 0000 05 0100 <BLOCK> <AUTH_TYPE> 00