首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用PN532和ArduinoMega从安卓手机读取NFC UID

问使用PN532和ArduinoMega从安卓手机读取NFC UID
EN

Stack Overflow用户
提问于 2021-04-18 08:01:57
回答 1查看 290关注 0票数 0

我正在尝试使用PN532从手机(三星Galaxy S10)读取我的NFC UID,但我只收到08和另外3位随机值。我读到以08开头的值是RID(随机ID)。有没有可能只读取一个唯一的值,或使用PN532读取一些独特的东西,从我的手机近场通信?我想使用该值将其与代码中的常量进行比较,并将脉冲发送到继电器以打开门。这段代码来自da Adafruit_PN532库。

代码语言:javascript
复制
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_PN532.h>

#define PN532_IRQ   (2)
#define PN532_RESET (3)  // Not connected by default on the NFC Shield

// Or use this line for a breakout or shield with an I2C connection:
Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET);

void setup(void) {
  Serial.begin(115200);
  Serial.println("Hello!");

  nfc.begin();

  uint32_t versiondata = nfc.getFirmwareVersion();
  if (! versiondata) {
    Serial.print("Didn't find PN53x board");
    while (1); // halt
  }

  Serial.print("Found chip PN5"); Serial.println((versiondata >> 24) & 0xFF, HEX);
  Serial.print("Firmware ver. "); Serial.print((versiondata >> 16) & 0xFF, DEC);
  Serial.print('.'); Serial.println((versiondata >> 8) & 0xFF, DEC);

  // configure board to read RFID tags
  nfc.SAMConfig();

  Serial.println("Waiting for an ISO14443A Card ...");
}


void loop(void) {
  uint8_t success;
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
  uint8_t uidLength;                        // Length of the UID (4 or 7 bytes depending on ISO14443A card type)

  // Wait for an ISO14443A type cards (Mifare, etc.).  When one is found
  // 'uid' will be populated with the UID, and uidLength will indicate
  // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);

  if (success) {
    // Display some basic information about the card
    Serial.println("Found an ISO14443A card");
    Serial.print("  UID Length: "); Serial.print(uidLength, DEC); Serial.println(" bytes");
    Serial.print("  UID Value: ");
    nfc.PrintHex(uid, uidLength);

    if (uidLength == 4) {
      // We probably have a Mifare Classic card ...
      uint32_t cardid = uid[0];
      cardid <<= 8;
      cardid |= uid[1];
      cardid <<= 8;
      cardid |= uid[2];
      cardid <<= 8;
      cardid |= uid[3];
      Serial.print("Seems to be a Mifare Classic card #");
      Serial.println(cardid);
    }
    delay(2000);
  }
}
EN

回答 1

Stack Overflow用户

发布于 2021-04-18 14:23:55

不要将NFC UID用于任何安全目的,因为您可以看到,出于隐私目的,电话确实会随机提供一个。

当多个不同的标签在范围内时,NFC UID仅用于帮助读取硬件处理将数据发送到正确的卡。不能保证UID实际上是唯一的,也不能保证它不能被复制(即使标签是在工厂编程的,你也可以从中国购买克隆,在那里它们可以由最终用户编程)。

如果使用电话来提供唯一性,则最好对存储在标签或模拟标签上的数据使用加密方法,以便将标签用于任何具有安全含义的内容。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67144046

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档