mifareClassicAuthenticateBlock method
void
mifareClassicAuthenticateBlock()
Authenticate specified block number for a MiFare classic card. uid: A byte array with the UID of the card. block_number: The block to authenticate. key_number: The key type (like MIFARE_CMD_AUTH_A or MIFARE_CMD_AUTH_B). A byte array with the key data.
Implementation
void mifareClassicAuthenticateBlock(
List<Uint8> uid, Uint8 blockNumber, Uint8 keyNumber, List<Uint8> key) {
// Build parameters for InDataExchange command to authenticate MiFare card.
List<int> parameters =
List.generate(3 + mifareKeyLength + uid.length, (_) => 0);
parameters[0] = 0x01;
parameters[1] = keyNumber.value;
parameters[2] = blockNumber.value;
// params[3:3+keylen] = key
for (int i = 0; i < mifareKeyLength; i++) {
parameters[3 + i] = key[i].value;
}
// params[3+keylen:] = uid
for (int i = 0; i < uid.length; i++) {
parameters[3 + mifareKeyLength + i] = uid[i].value;
}
List<int> response = callPN532Function(pn532CommandInDataExchange,
parameters: parameters, responseLength: 1);
if (response.first != pn532ErrorNone) {
throw PN532BadResponseException(
response: response,
additionalInformation:
"The first byte should be '$pn532ErrorNone' but it was '${response.first}'");
}
}