Reply To: Basic Tutorial for MIFARE Classic 1K using C#, C++ etc.

Forum MIFARE general topics and applications Basic Tutorial for MIFARE Classic 1K using C#, C++ etc. Reply To: Basic Tutorial for MIFARE Classic 1K using C#, C++ etc.

Re: Basic Tutorial for MIFARE Classic 1K using C#, C++ etc.

29. January 2016 at 17:04
Hi NTMS,

it seems you are using a proprietary class library. Let us assume you have a blank MIFARE Classic card. On a MIFARE Classic you have sectors with 4 blocks. Each block has the capacity of 16 bytes. The last block in a sector is the sector trailer and contains the keys. So you can use only the first 3 blocks for saving your data.

For the details, please visit:
http://www.nxp.com/documents/data_sheet/MF1S50YYX_V1.pdf

I do not know how the key store is implemented in your library but the scheme for interacting with the card in general could look like this:

char *pDefaultKey = "FFFFFFFFFFFF";
char *pDataToWrite = "00112233445566778899AABBCCDDEEFF"
char readBuffer[16];

openReader(); // Open the reader interface
connect(); // Connect to the card, if no card is detected, an error is returned!

authenticate( MIFARE_KEY_TYPE_A, 4, ... ); // Authenticate to sector 1 (block 4) with key A
updateBlock( 4, sizeof( pDataToWrite ), pDataToWrite ); // Write data to block 4
readBlock( 4, sizeof( readBuffer ), readBuffer ); // Read data from block 4

authenticate( MIFARE_KEY_TYPE_A, 8, ... ); // Authenticate to sector 2 (block 8) with key A
readBlock( 8, sizeof( readBuffer ), readBuffer ); // Read data from block 8

disconnect(); // Close connection
closeReader(); // Close interface


The variable
pDefaultKey
contains the factory key for a blank card. You have to authenticate to each sector you want to have access. But you can change the access conditions in the sector trailer – and also the keys.

Your library deals with key over the key store. So you have to load the default key into the key store and use the key store reference for the authentication method.

The MIFARE Team
+ 0  |  - 0