使用 ST25 android SDK 的 NFC 标签密码保护 [英] NFC-tag password protection with ST25 android SDK

查看:95
本文介绍了使用 ST25 android SDK 的 NFC 标签密码保护的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ST25 标签,更具体地说是 type5 标签 ST25DV64K.ST25 SDK for android 中有一些有趣的示例和教程.我仍在努力使用文档末尾提供的代码示例 此处关于受密码保护的数据,包含在这些行中:

I'm working with ST25 tags, more specifically type5 tags ST25DV64K. The ST25 SDK for android has some interesting examples and tutorials in it. I'm still struggling to use the code example provided at the end of the doc here concerning password-protected data, which consist in those lines:

byte[] password;
int passwordNumber = type5Tag.getPasswordNumber(area);
tag.presentPassword(passwordNumber, password);
NDEFMsg ndefMsg = myTag.readNdefMessage(area);

第一个问题,当我实例化一个 type5 标签时,我看不到 Type5Tag 类的那些方法:

first problem, when I instanciate a type5 tag i don't see those methods for Type5Tag class:

import com.st.st25sdk.type5.*;
Type5Tag tag5;
tag5.??

那么,我们一开始应该如何设置密码就不清楚了.我找不到任何为特定区域设置密码和删除密码的示例,我们可以使用的密码格式是什么?是否可以从 android 执行此操作,还是必须使用 ST25 应用程序?欢迎举例!谢谢.

Then, it is not clear how we are supposed to set up a password in the first place. I can't find any examples of setting up a password for a specific area, and removing it, and what is the format of the password that we can use? Is it possible to do this from android or do we have to use the ST25 app? Examples welcome! Thanks.

推荐答案

在 ST25 SDK Zip 文件中,您将找到一个使用 ST25 SDK 库的基本 Android 应用程序示例(位于 \integration\android\examples\ST25AndroidDemoApp).

In the ST25 SDK Zip file, you will find an example of a basic Android App using the ST25 SDK Library (it is in \integration\android\examples\ST25AndroidDemoApp).

此示例使用名为TagDiscovery"的类,该类能够识别任何 ST25 标签并实例化正确的对象.就您而言,如果您只使用 ST25DV64K 标签,您可能想要做一些简单的事情.

This example uses a class called "TagDiscovery" which is able to identify any ST25 Tag and to instantiate the right object. In your case, if you are only using ST25DV64K Tags, you will probably want to do something simple.

以下是我的建议:在您的 android 活动中,我希望您订阅了每次粘贴 NFC 标签时都会收到通知(在ST25AndroidDemoApp"示例中,查看 onResume() 函数中的 enableForegroundDispatch()).为了识别 Intent 是否对应于NFC Intent",我们检查 Intent 的 Action 是 ACTION_NDEF_DISCOVERED、ACTION_TECH_DISCOVERED 还是 ACTION_TAG_DISCOVERED.

Here is what I suggest you: In your android activity, I expect that you have subscribed to receive a notification every time an NFC tag is taped (in "ST25AndroidDemoApp" example, look at enableForegroundDispatch() in onResume() function). To identify if the Intent corresponds to an "NFC Intent", we check if the Intent’s Action is ACTION_NDEF_DISCOVERED, or ACTION_TECH_DISCOVERED or ACTION_TAG_DISCOVERED.

在这种情况下,我们知道这是 NFC Intent.然后我们可以调用它来获取 androidTag 的实例:

When this is the case, we know that it is an NFC Intent. We can then call this to get the instance of androidTag:

Tag androidTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);

此对象代表 Android 中的当前 NFC 标签.

This object represents the current NFC tag in Android.

我们现在要实例化一个 ST25DVTag 对象.

We’re now going to instantiate a ST25DVTag object.

import com.st.st25sdk.type5.st25dv.ST25DVTag;

…

AndroidReaderInterface readerInterface = AndroidReaderInterface.newInstance(androidTag);
byte[] uid = androidTag.getId();
uid = Helper.reverseByteArray(uid);
ST25DVTag myST25DVTag = new ST25DVTag(readerInterface, uid);

您现在有一个名为 myST25DVTag 的对象,可用于与标签通信!

You now have an object called myST25DVTag that can be used to communicate with the tag!

例如,如果您想使用密码:

For example, if you want to use the passwords:

byte[] password = new byte[];      // TODO: Fill the password
int passwordNumber = myST25DVTag.getPasswordNumber(area);
myST25DVTag.presentPassword(passwordNumber, password);
NDEFMsg ndefMsg = myST25DVTag.readNdefMessage(area);

在此之前,您需要检查与该区域关联的密码.标签有 3 个密码,可以自由分配到任何区域.默认情况下没有设置密码,所以你应该设置一个.这是我使用密码 2 作为 Area1 的示例:

Before doing that, you need to check which password is associated to this area. The tag has 3 passwords that can be freely assigned to any area. By default no password is set so you should set one. Here is an example where I use the password 2 for Area1:

int AREA1 = 1;
int passwordChosen = 2;
myST25DVTag.setPasswordNumber(AREA1, passwordChosen);
                           

我建议您从 Google Play 安装ST25 NFC Tap"Android 应用程序:https://play.google.com/store/apps/details?id=com.st.st25nfc&hl=fr&gl=US如果您点按 ST25DV 并进入区域安全状态"菜单,您将能够看到:区域数量、哪些区域受密码保护以进行读和/或写、使用哪些密码……等

I suggest that you install the "ST25 NFC Tap" Android App from Google Play: https://play.google.com/store/apps/details?id=com.st.st25nfc&hl=fr&gl=US If you tap you ST25DV and go to the "Areas Security Status" menu, you will be able to see: the number of areas, which ones are protected by password for read and/or write, which password is used…etc

如果您有兴趣,可以在此处获得此应用程序的源代码:https://www.st.com/en/embedded-software/stsw-st25001.html

If you are interested, the source code of this application is available here: https://www.st.com/en/embedded-software/stsw-st25001.html

如果有什么不清楚的,请告诉我.

Tell me if something is unclear.

免责声明:我是 ST25 SDK 开发团队的成员.

Disclaimer: I am on of the development team for the ST25 SDK.

这篇关于使用 ST25 android SDK 的 NFC 标签密码保护的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆