I have been trying to write some data to my mifare classic cards. first I send these two commands which returns 90 00:
Load Mifare Keys:
FF 82 20 01 06 FF FF FF FF FF FF
Authenticate:
FF 86 00 00 05 01 00 01 60 01
now I can write commands to sector 0 and block 1 + 2
ff d6 00 01 10 14 01 03 E1 03 E1 03 E1 03 E1 03 E1 03 E1 03 E1
ff d6 00 02 10 03 E1 03 E1 03 E1 03 E1 03 E1 03 E1 03 E1 03 E1
i mistakenly overwritten block 3 a few times rendering this sector unreadable it seems:
if I send the command ff d6 00 04 10 I get return error 69 82 which i googled as authentication error
do I need to authenticate to every sector? if so what is the command to do this for the next and following sectors?
yes, You have to authenticate every sector before read/write on the block of that sector.Now you have execute Authentication command and you overwrite the block 3(sector trailer) that means the keys and access right has been change.
APDU For Authenticate a Block:-
The APDU format for Authenticate a block should be in following format.
CLA+ INS+ P1+ P2+ Lc+ (Version + AddMSB + AddLSB + KeyID + KeyNumber)
For Example :-
CLA = FF
INS = 86
P1 = 00
P2 = 01 (Block Number for Authentication)
Lc = 05 (Length of Data Field)
Data Field = Version + AddMSB + AddLSB + KeyId + KeyNumber
Version=01
AddMSB=00
AddLSB=05 (Block Number)
KeyID=60/61 (60 for keyA and 61 for keyB)
KeyNo= 00 (Key Slot number of reader)
FF 86 00 00 05 01 00 05 60 00