Skip to content

Instantly share code, notes, and snippets.

@Gnzlt
Created January 17, 2022 20:00
Show Gist options
  • Save Gnzlt/7237a2a15d1ceadb046a06f5fe3b3171 to your computer and use it in GitHub Desktop.
Save Gnzlt/7237a2a15d1ceadb046a06f5fe3b3171 to your computer and use it in GitHub Desktop.
Android NFC MIFARE Classic utils
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