Good afternoon, I have an NFC tag with support for NfcA technology and MifareClassic. How to read label content using NfcA class Key to authenticate Mifare A0A1A2A3A4A5 technology

public static String[] readTag(Tag tag) { byte[] readedData; byte[] PASSWORD = new byte[]{(byte) 0xA0, (byte) 0xA1, (byte) 0xA2, (byte) 0xA3, (byte) 0xA4, (byte) 0xA5}; NfcA nfca = NfcA.get(tag); try { nfca.connect(); readedData = nfca.transceive(new byte[]{ (byte) 0x30, (byte) (0 & 0x0ff) // Π§Ρ‚Π΅Π½ΠΈΠ΅ ΠΏΠ΅Ρ€Π²ΠΎΠΉ страницы Π±Π΅Π· пароля, ΠΎΠ±Ρ‹Ρ‡Π½ΠΎΠΉ ΠΌΠ΅Ρ‚ΠΊΠΈ Π½Π΅ Mifare (для ΠΏΡ€ΠΈΠΌΠ΅Ρ€Π°) }); } catch (Exception e) { } } 

Commands to transceive

  • why don't you want to use the MifareClassic class? and what is the sacral meaning of this? - Lex Hobbit
  • It is necessary for the implementation of additional functions, thanks. - c0de
  • @LexHobbit maybe this will help you

1 answer 1

The most important thing is to check if your device supports reading the MIFARE Classic tag:

 public static boolean hasMifareClassicSupport() { if (mHasMifareClassicSupport != 0) { return mHasMifareClassicSupport == 1; } // провСряСм Π΅ΡΡ‚ΡŒ Π»ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° NFC Π½Π° устройствС if (NfcAdapter.getDefaultAdapter(mAppContext) == null) { mUseAsEditorOnly = true; mHasMifareClassicSupport = -1; return false; } // Π§ΠΈΠΏΡ‹ Broadcom Π½Π΅ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°ΡŽΡ‚ MIFARE Classic. File device = new File("/dev/bcm2079x-i2c"); if (device.exists()) { mHasMifareClassicSupport = -1; return false; } // Π§ΠΈΠΏΡ‹ NXP ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°ΡŽΡ‚ MIFARE Classic. device = new File("/dev/pn544"); if (device.exists()) { mHasMifareClassicSupport = 1; return true; } //провСряСм Π½Π°Π»ΠΈΡ‡ΠΈΠ΅ Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΡ‹Ρ… Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊ Π² систСмС File libsFolder = new File("/system/lib"); File[] libs = libsFolder.listFiles(); for (File lib : libs) { if (lib.isFile() && lib.getName().startsWith("libnfc") && lib.getName().contains("brcm") ) { mHasMifareClassicSupport = -1; return false; } } mHasMifareClassicSupport = 1; return true; } 

After that you can try to read. First authenticate using authenticateSectorWithKeyA() (if you have the A key, otherwise use authenticateSectorWithKeyB() with the B key). If you get false , the authentication failed (your key was incorrect).

When authentication is successful, you can use readBlock() to read the data (for convenience, you can use sectorToBlock() to convert from a sector index to a block index)

Do not worry about failed authentication: this will not affect the operation of your card.

The read readout using the algorithm described above can be found in the MifareClassicTool application.

  • This is not the answer to my question. I know how to read a map using MifareClassic technology. Question: how to read this tag using NfcA technology, if I have a key for Mifare technology - c0de
  • @ c0de you do not read well, the link for what you gave? - Lex Hobbit
  • You do not read the question posed by me. There is no implementation of reading the tag using NfcA technology. - c0de
  • @ c0de and the readSector method do you think it does here ? - Lex Hobbit
  • Reads a label using the MifareClassic class (technology). I need to read through the class NfcA - c0de