Created
January 17, 2022 20:00
-
-
Save Gnzlt/7237a2a15d1ceadb046a06f5fe3b3171 to your computer and use it in GitHub Desktop.
Android NFC MIFARE Classic utils
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example | |
import android.content.Context | |
import android.nfc.tech.MifareClassic | |
object NfcUtils { | |
fun Context.isMifareClassicCompatible(): Boolean = | |
packageManager.systemAvailableFeatures.any { it.name == "com.nxp.mifare" } | |
fun MifareClassic.authenticateSectorWithKeyA( | |
sectorIndex: Int, | |
keys: Array<ByteArray> | |
): Boolean { | |
keys.forEach { key -> | |
if (authenticateSectorWithKeyA(sectorIndex, key)) return true | |
} | |
return false | |
} | |
fun MifareClassic.authenticateSectorWithKeyB( | |
sectorIndex: Int, | |
keys: Array<ByteArray> | |
): Boolean { | |
keys.forEach { key -> | |
if (authenticateSectorWithKeyB(sectorIndex, key)) return true | |
} | |
return false | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment