【问题标题】:Initialize a NDEF tag on Windows 10 Desktop在 Windows 10 桌面上初始化 NDEF 标记
【发布时间】:2026-01-04 18:05:02
【问题描述】:

我正在尝试将新的 Mifare Classic 标签初始化为 DNEF 格式,可由 Proximity API 读取。

根据 Microsoft 的说法,proximity API 能够在需要时将 mifare 经典标签初始化为 NDEF 格式(如 herehere 所述)。

但是,使用这行代码发布消息:

proximityDevice.PublishBinaryMessage("NDEF:WriteTag", ndef.ToByteArray().AsBuffer(), MessageTransmittedHandler);

不要初始化 TAG 并写任何东西,只在预先格式化的 NDEF 标签上工作(例如,由 Android 手机完成)。

有什么方法可以在桌面系列上将 TAG 初始化为 NDEF 格式,将 NFC 读/写器作为感应设备? (NXP NearFieldProximity 提供商)


更新:

我从Onovotny 找到了一个适用于 .NET 的 MIRAFE API,其中包含将 APDU 数据发送到 Mifare 卡的所有低级操作,支持我正在使用的 WinRT SmartCard 框架。

现在问题在于尝试登录卡时的任何数据操作(getData 或 setData),产生此异常:

"The smart card has been reset, so any shared state information is invalid. (Exception from HRESULT: 0x80100068)"

我可以获得卡的识别信息,并且该卡在 Android 设备上是可写的。我还尝试将 KeyA 更改为 {0x00,0x00,0x00,0x00,0x00,0x00}, { 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF} 和 {0xA0,0xA1,0xA2,0xA3,0xA4,0xA5} 但是结果是一样的。

【问题讨论】:

    标签: c# uwp nfc desktop proximityapi


    【解决方案1】:

    刚刚在 services.msc 启动了一个 Windows 服务,名为 “智能卡设备枚举服务”,我可以向/从智能卡写入/读取数据。

    关于 NDEF 格式化,我在扇区 0、块 1 和 2 上插入了 MAD 数据。之后,在扇区 1、块 0..2 上添加了 NDEF 记录。然后,我像这样更新了 MAD 和 NDEF 扇区的 Key A 和 Key B:

    手动填写 MAD 和 2 条 NDEF 记录:

            //Atualiza KeyB
            mifareCard.AddOrUpdateSectorKeySet(new SectorKeySet {
                Key = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
                KeyType = KeyType.KeyB,
                Sector = 0
            });
            //Seta dados do MAD
            await mifareCard.SetData(0, 1, new byte[] { 0x14, 0x01, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1 });
            await mifareCard.SetData(0, 2, new byte[] { 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1 });
    
            mifareCard.AddOrUpdateSectorKeySet(new SectorKeySet {
                Key = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
                KeyType = KeyType.KeyB,
                Sector = 1
            });
            //Incluis dois records NDEF
            await mifareCard.SetData(1, 0, new byte[] { 0x00, 0x00, 0x03, 0x11, 0xD1, 0x01, 0x0D, 0x55, 0x01, 0x61, 0x64, 0x61, 0x66, 0x72, 0x75, 0x69 });
            await mifareCard.SetData(1, 1, new byte[] { 0x74, 0x2E, 0x63, 0x6F, 0x6D, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 });
    
            await mifareCard.Flush();
    

    更新 NDEF 记录的密钥:

            //Get MAD sector
            var setor = mifareCard.GetSector(0);
            //Get Trail data
            await setor.GetData(3);
            //Update chaves. Acess bits are generated by Mirafe API
            await setor.FlushTrailer(
                Extensions.ByteArrayToString(new byte[] { 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5 }),
                Extensions.ByteArrayToString(new byte[] { 0xD3, 0xF7, 0xD3, 0xF7, 0xD3, 0xF7 }
            ));
    
            //Set others sectors keys for NDEF
            for (var sector = 1; sector < 16; sector++) {
                try {
                    setor = mifareCard.GetSector(sector);
                    await setor.GetData(3);
                    await setor.FlushTrailer(
                        Extensions.ByteArrayToString(new byte[] { 0xD3, 0xF7, 0xD3, 0xF7, 0xD3, 0xF7 }),
                        Extensions.ByteArrayToString(new byte[] { 0xD3, 0xF7, 0xD3, 0xF7, 0xD3, 0xF7 }
                    ));
                } catch (Exception ex) {
                    Debug.Write(ex.Message + "\n");
                }
            }
    

    【讨论】:

      最近更新 更多