简体   繁体   English

使用CryptoTokenKit读取NFC(Mifare Classic 1K)

[英]Read NFC (Mifare Classic 1K) with CryptoTokenKit

I'm trying to read/write a Milfare Classic 1k NFC card (supplied from factory) using an ACR122. 我正在尝试使用ACR122读/写Milfare Classic 1k NFC卡(工厂提供)。 I can detect the card, but cannot communicate with it. 我可以检测到该卡,但是无法与其通信。

I have been searching the web for days trying to find any kind of documentation on this (without success). 我已经在网上搜索了几天,试图找到与此有关的任何类型的文档(没有成功)。

I know that these cards are encrypted but surely there is a default password or a way to reset the card? 我知道这些卡已加密,但是肯定有默认密码或重置卡的方法吗?

Here's what I have so far: 这是我到目前为止的内容:

card.beginSessionWithReply { (result, error) -> Void in
         print("Began card session: \(result) \(card.valid) \(card.currentProtocol)");

         let aid : [UInt8] = [0xFF, 0x86, 0x00, 0x00, 0x05, 0x01, 0x00, 0x00, 0x0, 0x00];
         var data = NSData(bytes: aid, length: aid.count)
         card.transmitRequest(data, reply: { (data, error) -> Void in
            print("Transmit: data: \(data) error \(error)");
         })

         data = "Hi".dataUsingEncoding(NSUTF8StringEncoding)!;
         card.sendIns(0xFF, p1: 0x00, p2: 0x00, data: data, le: nil, reply: { (data, uint, error) -> Void in
            if let e = error {
               if (e.code == TKErrorCode.CorruptedData.rawValue) {
                  print("CorruptedData");
               } else {
                  print("error code: \(error?.code)");
               }
            }
            print("Sendins: reply:\(data) int:\(uint) error:\(error)");
         })
      }

Output: 输出:

["ACS ACR122U"]
Card is valid
ATR: <3b8f8001 804f0ca0 00000306 03000100 0000006a>
Began card session: true true TKSmartCardProtocol(rawValue: 2)
error code: Optional(-2)
Sendins: reply:nil int:0 error:Optional(Error Domain=CryptoTokenKit Code=-2 "(null)")
Transmit: data: Optional(<6300>) error nil

Any suggestions would be great (including any OS X software capable of reading/writing these cards). 任何建议都会很棒(包括任何能够读取/写入这些卡的OS X软件)。

I'm not sure about CryptoTokenKit but i'm sure we can use PICC commands according to ACR122 Application Programming Interface to read/write Mifare Cards. 我不确定CryptoTokenKit,但我确定我们可以根据ACR122 应用程序编程接口使用PICC命令来读取/写入Mifare卡。

You have to go through following steps. 您必须执行以下步骤。

  1. Load authentication keys to the reader. 将身份验证密钥加载到读取器。 在此处输入图片说明

  2. Do authentication. 进行身份验证。

You need to provide which set of blocks to read and provide authentication key for those. 您需要提供要读取的一组块并为其提供身份验证密钥。 For more info on memory structure of Mifare classic 1k please refer to the datasheet here . 有关Mifare classic 1k存储器结构的更多信息,请参考此处的数据表。

在此处输入图片说明

Then you can issue read and write APDU commands (can be found of ACR 122 API documentation). 然后,您可以发出读写APDU命令(可以在ACR 122 API文档中找到)。 Cheers! 干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM