如果标签为空,如何初始化Nfc标签,并使其在Xamarin Android中受密码保护?

如果标签为空,如何初始化Nfc标签,并使其在Xamarin Android中受密码保护?,xamarin,xamarin.android,nfc,Xamarin,Xamarin.android,Nfc,我在nfc标签中使用收费数据的代码,若标签已经初始化并受密码保护,它就会工作。但我面临初始化空标记的问题,我想设置标记的密码。如何做到这一点 我的已验证标记代码为: commandResponse = mifareUltralight.Transceive(getAuthenticateCmd()); 验证方法是: internal byte[] getAuthenticateCmd() { return new byte[5] { 0x1b,

我在nfc标签中使用收费数据的代码,若标签已经初始化并受密码保护,它就会工作。但我面临初始化空标记的问题,我想设置标记的密码。如何做到这一点

我的已验证标记代码为:

commandResponse = mifareUltralight.Transceive(getAuthenticateCmd());
验证方法是:

internal byte[] getAuthenticateCmd()
    {
        return new byte[5] {
            0x1b,
            password[0],
            password[1],
            password[2],
            password[3]
        };
    }
其中密码为:

internal byte[] password = new byte[4] { 0x39, 0x39, 0x39, 0x39 };

当我尝试使用此代码验证空标记时,它会引发TagLostException。

首先,您应该检查标记是否通过读取auth0受到保护,我建议您使用此代码片段:

boolean isTagProtected() {
    MifareUltralight mu = MifareUltralight.get(tag);
    boolean passExist;
    try {
        mu.connect();
        byte[] answer = mu.readPages(227);
        byte auth0 = answer[3];
        String text = String.format("%02x", auth0);
        Toast.makeText(context, text, Toast.LENGTH_LONG).show();
        passExist = auth0 < (byte) 0xEB;
        mu.close();
    } catch (IOException e) {
        e.printStackTrace();
        Toast.makeText(context, "cannot make authentication", Toast.LENGTH_SHORT).show();
        passExist = true;
    }
    return passExist;
}
如果标签受到保护,您可以对其进行身份验证,使其能够在一个会话中读取和写入标签

以下是如何清除密码:

private final byte[] pwd_auth = new byte[]{(byte) 0x1b, 
//here write your pass (4 bytes)
};
public static final byte[] RESET_PACK_VALUE = {(byte) 0xA2, (byte) 0xE6, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00};
public static final byte[] RESET_AUTH0_VALUE = {(byte) 0xA2, (byte) 0xE3, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xFF};

MifareUltralight mfu = MifareUltralight.get(maintag);
try {
     byte[] answer;
     mfu.connect();

     answer = mfu.transceive(pwd_auth);
     mfu.transceive(MainActivity.RESET_AUTH0_VALUE);
     mfu.transceive(MainActivity.RESET_PACK_VALUE);
     mfu.close();
     Toast.makeText(context, "The Password is deleted", Toast.LENGTH_LONG).show();
     } catch (IOException e) {
           Toast.makeText(context, "Error happend , wrong pass", Toast.LENGTH_LONG).show();
           e.printStackTrace();
      }
换句话说,您正在尝试验证一个没有任何密码的标记。 您应该先设置密码,然后对其进行身份验证

更一般的细节:

以下是有关tag tech的更多详细信息: 在处理密码时,需要编辑其中一些参数的四个参数是:

PWD用于内存访问保护的32位密码。 读取PWD始终返回00000000小时

PACK16位密码确认在密码输入过程中使用 身份验证过程。 读取包始终返回0000h

AUTH0从其开始输入密码的扇区0的页面地址 从NFC访问用户内存需要身份验证 透视图,取决于NFC_保护位。 如果AUTH0设置为大于EBh的页面地址,则 密码保护被有效禁用。密码保护 区域从页面AUTH0开始,在页面EBh结束

AUTHLIM此处无需解释


注:我正在使用NT3H2111_2211 u-should阅读Andrew在评论中的链接,以确切了解您应该在哪里编写PACK、PWD和AUTH0。

这不是很明显吗?我的意思是,标记的整个概念是基于这样一个前提,即您指定的标记应该是非空的。如果标签因为某种原因是空的,你不能想出一个默认标签吗?对不起,我对此一无所知。您可以分享一些代码吗?您的标签是如何变为空的?请分享标签型号的详细信息,因为设置密码的方法是特定于标签的type@FreakyAli,我从客户那里得到了空标签。不知道怎么做。这是密码吗?你能分享一下复位或格式化卡的代码吗?我用“isTagProtected”的方法每次都是真的。在这里,我只是用一个A2h命令和一个字节作为页码来写。我的密码是
(字节)0x75,(字节)0x6C,(字节)0x66,(字节)0x30
。我的密码很长,你应该告诉我你想让我共享哪个功能。如果你的卡受到保护,你需要知道密码并对卡进行身份验证。覆盖旧密码,我将共享代码如何删除密码并打开卡,我猜你知道标签的密码吗?@srusthakkar试着阅读这个问题的公认答案
private final byte[] pwd_auth = new byte[]{(byte) 0x1b, 
//here write your pass (4 bytes)
};
public static final byte[] RESET_PACK_VALUE = {(byte) 0xA2, (byte) 0xE6, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00};
public static final byte[] RESET_AUTH0_VALUE = {(byte) 0xA2, (byte) 0xE3, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xFF};

MifareUltralight mfu = MifareUltralight.get(maintag);
try {
     byte[] answer;
     mfu.connect();

     answer = mfu.transceive(pwd_auth);
     mfu.transceive(MainActivity.RESET_AUTH0_VALUE);
     mfu.transceive(MainActivity.RESET_PACK_VALUE);
     mfu.close();
     Toast.makeText(context, "The Password is deleted", Toast.LENGTH_LONG).show();
     } catch (IOException e) {
           Toast.makeText(context, "Error happend , wrong pass", Toast.LENGTH_LONG).show();
           e.printStackTrace();
      }