public interface MifareCard extends MemoryCard
MifareCard
interface for managing Mifare contactless memory cards.
Complies with MIFARE international standards, facilitating secure interactions
like authentication, data reading/writing, and managing E-Wallet functionalities.PROTOCOL_RFCARD_TYPE_A, PROTOCOL_RFCARD_TYPE_B, PROTOCOL_T_0, PROTOCOL_T_1, PROTOCOL_UNKNOWN, STATUS_ABSENT, STATUS_CONNECTED, STATUS_DISCONNECTED
Modifier and Type | Method and Description |
---|---|
boolean |
decreaseValue(int sectorIndex,
int blockOfSector,
int value)
Decreases the E-Wallet data value in a block.
|
boolean |
increaseValue(int sectorIndex,
int blockOfSector,
int value)
Increases the E-Wallet data value in a block.
|
byte[] |
readBlock(int sectorIndex,
int blockOfSector)
Reads data from a specified block within a sector.
|
MoneyValue |
readValue(int sectorIndex,
int blockOfSector)
Reads E-Wallet data from a specified block.
|
byte[] |
transmit(byte[] apdu,
int operation)
Transmits a command at level 3 and receives a response.
|
boolean |
verifyKeyA(int sectorIndex,
byte[] key)
Authenticates a sector with Key A.
|
boolean |
verifyKeyB(int sectorIndex,
byte[] key)
Authenticates a sector with Key B.
|
void |
writeBlock(int sectorIndex,
int blockOfSector,
byte[] buffer)
Writes data to a specified block within a sector.
|
void |
writeValue(int sectorIndex,
int blockOfSector,
MoneyValue value)
Writes data to the E-Wallet in a specified block.
|
getCardStatus, getID, getIDInfo, getProtocol
boolean verifyKeyA(int sectorIndex, byte[] key) throws DeviceException
Allows performing I/O operations on a sector after successful authentication. The operations permissible are determined by the ACL settings of the sector. Note: Failure in authentication resets the card's connection, affecting other sectors. This method is a blocking I/O operation and should not be called on the main application thread.
sectorIndex
- The sector number on the Mifare card.key
- The 6-byte Key A for authentication.DeviceException
- for standard device-related errors as documented in DeviceException
.boolean verifyKeyB(int sectorIndex, byte[] key) throws DeviceException
Similar to verifyKeyA, but utilizes Key B for authentication. It is essential for accessing different operations based on the sector's ACL settings. A failed attempt at authentication will result in a reset of the card's connection. Avoid calling this method on the main thread due to its blocking nature.
sectorIndex
- The sector number on the Mifare card.key
- The 6-byte Key B.DeviceException
- for standard device-related errors as documented in DeviceException
.byte[] readBlock(int sectorIndex, int blockOfSector) throws DeviceException
This method retrieves data from a block within a given sector. Ensure that the sector is authenticated before attempting to read from it.
sectorIndex
- The sector index.blockOfSector
- The block number within the sector.DeviceException
- for standard device-related errors as documented in DeviceException
.void writeBlock(int sectorIndex, int blockOfSector, byte[] buffer) throws DeviceException
Allows writing data to a block within an authenticated sector. The data to be written is passed as a byte array.
sectorIndex
- The sector index.blockOfSector
- The block number within the sector.buffer
- The byte array containing data to be written.DeviceException
- for standard device-related errors as documented in DeviceException
.void writeValue(int sectorIndex, int blockOfSector, MoneyValue value) throws DeviceException
This method is used for writing E-Wallet data to a particular block within a sector. The value parameter represents the E-Wallet data to be written.
sectorIndex
- The sector index.blockOfSector
- The block number within the sector.value
- The E-Wallet data to be written.DeviceException
- for standard device-related errors as documented in DeviceException
.MoneyValue readValue(int sectorIndex, int blockOfSector) throws DeviceException
Retrieves E-Wallet data from a block within a sector. The method returns the data as a MoneyValue object.
sectorIndex
- The sector index.blockOfSector
- The block number within the sector.DeviceException
- for standard device-related errors as documented in DeviceException
.boolean increaseValue(int sectorIndex, int blockOfSector, int value) throws DeviceException
Increment the value of E-Wallet data in a specified block. The value parameter specifies the amount to increase.
sectorIndex
- The sector index.blockOfSector
- The block number within the sector.value
- The amount to increase the E-Wallet data by.DeviceException
- for standard device-related errors as documented in DeviceException
.boolean decreaseValue(int sectorIndex, int blockOfSector, int value) throws DeviceException
Decrements the value of E-Wallet data in a specified block. The value parameter specifies the amount to decrease.
sectorIndex
- The sector index.blockOfSector
- The block number within the sector.value
- The amount to decrease the E-Wallet data by.DeviceException
- for standard device-related errors as documented in DeviceException
.byte[] transmit(byte[] apdu, int operation) throws DeviceException
Sends an APDU command to the Mifare card and receives the response. The operation parameter sets the command mode.
apdu
- The data buffer to be transmitted.operation
- The operation mode (default is 0, set to 16 to disable CRC and parity).DeviceException
- for standard device-related errors as documented in DeviceException
.