简体   繁体   中英

Mifare Classic 1k write keys

I'm trying to make an Android application to write NFC tags. To see how to do that, I've downloaded an example. However, the example does not work. It says it can't authenticate. That can only mean that it uses an incorrect key for this type of card. The strange thing is, even the KEY_DEFAULT and KEY_MIFARE_APPLICATION_DIRECTORY keys are not working on my blank cards. Did Mifare change the keys in any way?

EDIT: here's my code.

            /* Authenticate the MAD Sector, sector 1, with key A */
        succes = mClassic.authenticateSectorWithKeyA(
                1, key);
        if (succes) {
            /* Authentication succeeded */

            /*
             * This will read a 16-byte block in this sector
             * It is an I/O operation and will block until complete.
             * It must not be called from the main application thread.
             **/
            b.append(mClassic.readBlock(1), 0, 16);
            b.append(mClassic.readBlock(2), 0, 16);
            b.append(mClassic.readBlock(3), 0, 16);
            data = b.toByteArray();
        }
        /* Authentication failed */
        else
            sb.append("Authentication failed");
        mClassic.close();

    }

I've tried it with the following keys already:

MifareClassic.KEY_DEFAULT
MifareClassic.KEY_MIFARE_APPLICATION_DIRECTORY
00 00 00 00 00 00
ff ff ff ff ff ff

all to no avail..

I am not familiar with the Ubiqconn Tablet PC. First thing I would do is to check whether the NFC implementation in the device actually supports MIFARE. In your main activity's onCreate() add:

public void onCreate(Bundle bundle) {
  ...
  if (!getPackageManager().hasSystemFeature("com.nxp.mifare")) {
    Toast.makeText(this, "No MIFARE support!", Toast.LENGTH_LONG).show();
  }
}

Either you have bug in your app(s), or the keys have been customized. Use an app like NFC TagInfo to check whether you can read/write the cards with default keys. If it doesn't work, contact whoever sold you the cards and ask them what are the keys.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM