2

我需要找到一种解决方案来使用自定义密钥编写 Mifare Classic 1 K 标签。我无法编写它,我尝试了所有选项,但不幸的是我一直收到错误“IOException:Transceive Failed”。

下面是我的代码片段:

byte custom_key[]={
  (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff
};

// 16 bytes of Data. Otherwise it was throwing IllegalArgumentException .
byte[] data="Hello world of N".getBytes();
getMfc().connect();

if(getMfc().authenticateSectorWithKeyA(4, custom_key)) {
  getMfc().writeBlock(3, data); // Here I receive IOException all the time.
} else {
  getMfc().close();
}

请在这方面帮助我。我需要用自己的密钥编写 Mifare Classic 1 K Tag。

4

2 回答 2

6

您对扇区 4 进行身份验证,然后尝试写入块 3。块 3 在扇区 0 中,因此这将始终失败。请尝试对扇区 0 进行身份验证。

顺便说一句:请不要将随机数据写入扇区尾部(例如块 3)。它可能会锁定该行业而无法恢复。

于 2012-10-31T10:00:25.133 回答
0

如果我理解正确,问题是如何编辑扇区 4
中的块 3。身份验证后,您尝试写入块 3。但是:
块编号不是在每个块中从 0 开始。扇区 0 具有块 0-3,扇区 1 具有块 4-7,依此类推。扇区 4 的块偏移量为 4*4=16。所以你要写入的块是块 19。

有一个函数可以为您计算这个偏移量。ectorToBlock(4) 产生 16。
对于写入扇区 4 中的块 3,我将使用以下命令:
getMfc().writeBlock(getMfc().sectorToBlock(4)+3, data)

接受的答案仅提供了使提问者无法理解扇区 0 以外的块索引的替代方案。

于 2015-01-15T08:17:08.520 回答