# Class MifareClassic

java.lang.Object
com.codename1.nfc.TagTechnology
com.codename1.nfc.MifareClassic

public class MifareClassic extends TagTechnology

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
  Constructor
  Description
  `MifareClassic()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `AsyncResource<Boolean>`
  `authenticateSectorWithKeyA(int sector, byte[] key)`
  Authenticates a sector with the given key A.
  `AsyncResource<Boolean>`
  `authenticateSectorWithKeyB(int sector, byte[] key)`
  Authenticates a sector with the given key B.
  `int`
  `getBlockCount()`
  Total addressable blocks (each 16 bytes).
  `int`
  `getSectorCount()`
  Total sectors on the tag (16 on Classic 1K, 40 on Classic 4K).
  `final TagType`
  `getType()`
  The technology variant this view represents.
  `static byte[]`
  `keyDefault()`
  Default MIFARE Classic key A used by NXP shipping cards (`FF FF FF FF FF FF`).
  `static byte[]`
  `keyMifareApplicationDirectory()`
  MIFARE Application Directory (MAD) key A from NXP AN10787 (`A0 A1 A2 A3 A4 A5`).
  `static byte[]`
  `keyNfcForum()`
  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.
  `int`
  `sectorToBlock(int sectorIndex)`
  First block index inside the given sector.
  `AsyncResource<Boolean>`
  `writeBlock(int block, byte[] data)`
  Writes the 16-byte payload to the given data block.

  ### Methods inherited from class TagTechnology

  `transceive`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## 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

    public AsyncResource<Boolean> authenticateSectorWithKeyA(int sector, byte[] key)
    Authenticates a sector with the given key A. Required before any read/write on the sector. Fails with `NfcError.IO_ERROR` when the key is wrong.

  - ### authenticateSectorWithKeyB

    public AsyncResource<Boolean> authenticateSectorWithKeyB(int sector, byte[] key)
    Authenticates a sector with the given key B.

  - ### readBlock

    public AsyncResource<byte[]> readBlock(int block)
    Reads a single 16-byte data block. The sector containing the block must have been authenticated first.

  - ### writeBlock

    public AsyncResource<Boolean> writeBlock(int block, byte[] data)
    Writes the 16-byte payload to the given data block. Fails with `NfcError.READ_ONLY` when access bits forbid the write.

  - ### getType

    public final TagType getType()
    Description copied from class: `TagTechnology`
    The technology variant this view represents.
    Specified by:
      `getType` in class `TagTechnology`