1
votes

I'm using the pcsc-sharp library to communicate with an ACR122U Reader an read/write information to MIFARE Classic 1k cards.

After getting familiar with the library and the APDU concept I'm able to use the cards UID as identifier in my applications. Now I am in need of setting my own ID's to the card. Therefore I read some manuals regarding NXP's MIFARE (like MF1S70YYX_V1) and also got some information about ISO 7816-4.

I'm aware of the need to do authentication before accessing the cards memory to perform read/write operations and I know the standard Key value.

I downloaded the pcsc-sharp examples from GitHub and ran the Mifare1kTest example. I works but card.LoadKey in Line 36 fails. The response values of the Apdu command in LoadKey is SW1=99 SW2=0, which I cannot find in any documentation. Commenting out the "throw new Exception" section makes the example work.

My question now is, which values are the correct ones to pass to Card.LoadKey, respectively which are the correct values to use for parameters in the Apdu Command. What is meant with "keynumber" (Sectornumber - Sector/Block Combination)? Is the LoadKey call necessary, if the example works?

1
Usually anything in the 9xxx range means success, with the xxx being additional information. If I remember correctly the APDU wrap will put the MiFare response within the status word (but hey, I've programmed the interface in one day, some year ago, my mind isn't that young anymore). Have you tried if the key load was successful by using the key?Maarten Bodewes
The key has to be loaded in the volatile part of the readers memory. The example Hands over 'KeyStructure,NonVolalatileMemory'. Doing so as described Mr Heart in answer below the example works. The results for SW1 / SW2 are 90 00. Thank you very much.Matthias Fuchs

1 Answers

2
votes

Your question is broad, but these should work for you. Code is explained with comments

var loadKeySuccessful = card.LoadKey(
    KeyStructure.VolatileMemory,
    0x00, // first key slot
    new byte[] {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} // key
);