在Android上清除MifareClassic扇区的最佳方法是什么?

时间:2018-08-29 11:02:19

标签: android kotlin format nfc mifare

有没有比在MIFARE Classic卡上写全零更好的方法了?

这是我当前代码的示例:

for (i in 0 until sectorCount) {
    if (!authenticateSectorWithKeyA(i, key) && !authenticateSectorWithKeyA(i, MifareClassic.KEY_DEFAULT)) {
        break
    }

    val idx = sectorToBlock(i)

    for (j in 0 until getBlockCountInSector(i)) {
        val index = idx + j
        when (index) {
            0 -> cardId = getCardId(readBlock(idx + j))
            1 -> {} //Todo: Write specail data
            4 -> {} //Todo: Write specail data
            5 -> {} //Todo: Write specail data
            else -> {
                if ((index + 1) % 4 != 0) {
                    writeBlock(index, ByteArray(16).apply { fill(0.toByte()) })
                }
            }
        }
    }
}

0 个答案:

没有答案