Search code examples
androidnfcaccess-controlrfidmifare

Make MIFARE Classic 1K read only through an Android app


I would like to make MIFARE Classic 1k cards read only after writing some initial data to them. I guess I need to change keys A and B to something custom after writing data to the new card. But how do I do that? These keys are located in the same block as the access bits, so I can't use MifareClassic method for writing a complete block:

public void writeBlock(int blockIndex, byte[] data) throws IOException

because it will also rewrite the access bits.


Solution

  • Sure you need to use the method MifareClassic.writeBlock(). Since MIFARE Classic only supports writing complete blocks, you have to update the whole sector trailer block.

    As MIFARE Classic does not have a free read mode (i.e. read without prior authentication) you need to set both, a read key (you would typically use key A for that) and the access bits (that cofigure key A as read-only key).

    You can find further information about possible access condition values and the block format here: