pcsc-sharp Mifare Authentication

2.1k views Asked by At

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

There are 1 answers

2
Mr Heart On BEST ANSWER

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
);