我正在编写一个使用NFC标签的Android应用程序,以便传输一些信息。目前我有读取功能,从NFC标签读取内容:
protected NdefMessage[] getNdefMessages(Intent intent) {
// Parse the intent
NdefMessage[] msgs = null;
String action = intent.getAction();
if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(action)
|| NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {
Parcelable[] rawMsgs =
intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
if (rawMsgs != null) {
msgs = new NdefMessage[rawMsgs.length];
for (int i = 0; i < rawMsgs.length; i++) {
msgs[i] = (NdefMessage) rawMsgs[i];
}
} else {
// Unknown tag type
byte[] empty = new byte[] {};
NdefRecord record = new NdefRecord(NdefRecord.TNF_UNKNOWN, empty, empty, empty);
NdefMessage msg = new NdefMessage(new NdefRecord[] {
record
});
msgs = new NdefMessage[] {
msg
};
}
} else {
finish();
}
return msgs;
}
现在,我想为通信添加安全性,即SSL。但是,我真的不知道为了实现这个功能我必须采取什么步骤。 是否有一些NFCSecurity类或类似的东西,为您完成所有工作?
有什么想法吗?
答案 0 :(得分:2)
通过Android NFC API,您可以访问标签上的(低级)标签通信和(高级)NDEF消息存储(或通过Android Beam传输)。
增加安全性,同时仍然保留自动NDEF消息读取和写入的好处,可以通过加密您使用的NdefRecord
的有效负载来完成。
SSL / TLS适用于连接级别。据我所知,没有标签支持这样的事情。您可以考虑将SSL / TLS添加到NFC对等通信中,但目前还不存在。它将涉及修改Android NFC堆栈并构建自定义Android系统映像(如果可能的话)。它不是可以通过应用程序在Android Beam上添加的东西。