Class MifareClassic
java.lang.Object
com.codename1.nfc.TagTechnology
com.codename1.nfc.MifareClassic
NXP MIFARE Classic 1K/4K technology view. Block-level read and write with key A or key B authentication.
Android-only -- iOS Core NFC intentionally rejects MIFARE Classic.
On iOS, Tag.getMifareClassic() returns null for the same physical
tag and the caller should fall back to Tag.getNfcA() or fail
gracefully.
The default factory keys are widely published; use them only on untransitioned demo / blank cards.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionauthenticateSectorWithKeyA(int sector, byte[] key) Authenticates a sector with the given key A.authenticateSectorWithKeyB(int sector, byte[] key) Authenticates a sector with the given key B.intTotal addressable blocks (each 16 bytes).intTotal sectors on the tag (16 on Classic 1K, 40 on Classic 4K).final TagTypegetType()The technology variant this view represents.static byte[]Default MIFARE Classic key A used by NXP shipping cards (FF FF FF FF FF FF).static byte[]MIFARE Application Directory (MAD) key A from NXP AN10787 (A0 A1 A2 A3 A4 A5).static byte[]NFC Forum key A for NDEF-formatted MIFARE Classic blocks (D3 F7 D3 F7 D3 F7).AsyncResource<byte[]> readBlock(int block) Reads a single 16-byte data block.intsectorToBlock(int sectorIndex) First block index inside the given sector.writeBlock(int block, byte[] data) Writes the 16-byte payload to the given data block.Methods inherited from class TagTechnology
transceive
-
Constructor Details
-
MifareClassic
public MifareClassic()
-
-
Method Details
-
keyDefault
public static byte[] keyDefault()Default MIFARE Classic key A used by NXP shipping cards (FF FF FF FF FF FF). Returns a fresh defensive copy. -
keyMifareApplicationDirectory
public static byte[] keyMifareApplicationDirectory()MIFARE Application Directory (MAD) key A from NXP AN10787 (A0 A1 A2 A3 A4 A5). Returns a fresh defensive copy. -
keyNfcForum
public static byte[] keyNfcForum()NFC Forum key A for NDEF-formatted MIFARE Classic blocks (D3 F7 D3 F7 D3 F7). Returns a fresh defensive copy. -
getSectorCount
public int getSectorCount()Total sectors on the tag (16 on Classic 1K, 40 on Classic 4K). -
getBlockCount
public int getBlockCount()Total addressable blocks (each 16 bytes). -
sectorToBlock
public int sectorToBlock(int sectorIndex) First block index inside the given sector. Sectors 0-31 contain 4 blocks each; sectors 32-39 (4K cards only) contain 16 blocks. -
authenticateSectorWithKeyA
Authenticates a sector with the given key A. Required before any read/write on the sector. Fails withNfcError.IO_ERRORwhen the key is wrong. -
authenticateSectorWithKeyB
Authenticates a sector with the given key B. -
readBlock
Reads a single 16-byte data block. The sector containing the block must have been authenticated first. -
writeBlock
Writes the 16-byte payload to the given data block. Fails withNfcError.READ_ONLYwhen access bits forbid the write. -
getType
Description copied from class:TagTechnologyThe technology variant this view represents.- Specified by:
getTypein classTagTechnology
-