AnsweredAssumed Answered

NTAG213 PWD_AUTH Android problem.

Question asked by Dejan Cencelj on May 23, 2017
Latest reply on Jun 20, 2017 by Wigros Sun

Hello!

 

I tried to implement password lock protection in my Android app. I was able to set the password and set the AUTH0 byte to 0.

 

But I'm not able to authenticate the tag. I always get Tag was lost exception. I tried both Android NfcA and MirafeUltralight from Android SDK... and got same result.

 

Code bellow is how I try to autheticate

 

   Tag tag = savedIntent.getParcelableExtra(NfcAdapter.EXTRA_TAG);

   NfcNtag nfca = NfcNtag.get(tag);


   try {
     nfca.connect();
   
     byte[] pin = new byte[4];

     pin[0] = 97;
     pin[1] = 97;
     pin[2] = 97;
     pin[3] = 97;
     byte[] response = nfca.pwdAuth(pin);

   } catch (IOException e) {
     e.printStackTrace();
   }finally {
     if (nfca != null) {
       try {
         nfca.close();
       }
       catch (IOException e) {
         Log.e(TAG, "Error closing tag...", e);
       }
     }
   }

 

  public byte[] pwdAuth(byte[] password) {

    if (password == null) {
        return null;
    }
    if (password.length != 4) {
        return null;
    }

    byte[] req = new byte[5];
    byte[] resp;

    req[0] = NfcNtagOpcode.PWD_AUTH; //0x2B

    try {
        System.arraycopy(password, 0, req, 1, 4);
        resp = nfca.transceive(req);
    } catch (IOException ex) {
        ex.printStackTrace(); //Allways ends here
        resp = null;
    }
    return resp; // result will be the PACK
}

 

I used code from bellow

 

smartrac-sdk-java-android-nfc/NfcNtag.java at master · SMARTRACTECHNOLOGY-PUBLIC/smartrac-sdk-java-android-nfc · GitHub 

Outcomes