Search code examples
androidnfcrfidmifarecontactless-smartcard

Cannot authenticate a sector in mifare card with correct key in android


I have a mifare classic 1K card and custom Key. But unable to read/write using it. Need help to find my mistake.

I have identified the key that is used to read/write the mifare card using NXP Taginfo and Mifare Classic Tool. It shows access bits as FF078000 and Key B is 222222222222 Now I am using Key B to read the data from the mifare classic 1K card. Below is the code.

NXP Taginfo tool output is here.

byte[] newkey = {(byte)0x00, (byte)0x33,(byte)0xBD,(byte)0x7A,(byte)0x03,(byte)0x8E};

boolean authB = taskTag.authenticateSectorWithKeyB(6, newkey);
Log.i("New Key"+ new BigInteger(newkey).toString(), "authB : " + authB) ;

But authB is returning false. what is wrong here?

Any help is much appreciated.

Edit-1:

After extensive reading I figured I may have interpreted the access conditions wrongly. I think I may need to authenticate with Key A. But as per the access conditions key A is not readable. Am I correct here?

Edit-2

How come nxp tag editinfo/Mifare Classic Tool are able to read the data with the key as 222222222222 but I cannot?


Solution

  • I figured that the problem was with the key. I have to use 222222222222 as the key not it's hex form. so changing the key to the below line resolved the issue.

    newkey = {(byte)0x22, (byte)0x22,(byte)0x22,(byte)0x22,(byte)0x22,(byte)0x22};