Was ist die korrekte Prozedur für das Festlegen eines Schreibschutzkennworts auf einem NXP NNTAG213-Tag?Android

Forum für diejenigen, die für Android programmieren
Anonymous
 Was ist die korrekte Prozedur für das Festlegen eines Schreibschutzkennworts auf einem NXP NNTAG213-Tag?

Post by Anonymous »

Ich arbeite an einem NFC -Tag -Projekt, bei dem ich eine öffentliche ID auf die Tags codiert. Eine wichtige Anforderung besteht darin, diese ID mit einem Passwort zu schützen und nicht autorisierte Umschreiben zu verhindern. Ich habe eine Helferklasse erstellt, um Passwörter zu verwalten, aber ich habe einige Probleme mit: < /p>
Kennwort zurückgesetzt: Ich kann mit meiner Helferklasse Passwörter einstellen und entfernen. Nach dem Einstellen eines Kennworts kann ich es jedoch mithilfe eines externen NFC -Tools (wie NFC -Tools) nicht zurücksetzen, selbst wenn ich das richtige Kennwort angreife. Ich kann das Kennwort mit meiner eigenen Helferklasse entfernen. .

Code: Select all

fun isPasswordProtected(tag: Tag): Boolean {
val nfcA = NfcA.get(tag)
try {
nfcA.connect()
// Read page 41 (0x29)
val response = nfcA.transceive(byteArrayOf(0x30, 0x29))
// Get the AUTH0 byte (first byte of the response)
val auth0 = response[0]
// Password protection is enabled if AUTH0 is less than 0xFF
return auth0 < 0xFF.toByte()
} catch (e: IOException) {
LogUtil.log(LogUtil.TAG_NFC, "IOException while reading NFC-A tag -> ${e.message}")
return false // Or handle the exception as needed
} finally {
try {
nfcA.close()
} catch (e: IOException) {
LogUtil.log(LogUtil.TAG_NFC,"IOException while closing NFC-A tag -> ${e.message}")
}
}

}

fun writeProtectWithPassword(tag: Tag, password: String, pack: String) {
val nfcA = NfcA.get(tag)
try {
nfcA.connect()
val passwordBytes = password.toByteArray(Charset.forName("US-ASCII"))
val packBytes = pack.toByteArray(Charset.forName("US-ASCII"))
// Write password to page 43 (0x2B)
nfcA.transceive(byteArrayOf(0xA2.toByte(), 0x2B, passwordBytes[0], passwordBytes[1], passwordBytes[2], passwordBytes[3]))
// Write PACK to page 44 (0x2C)
nfcA.transceive(byteArrayOf(0xA2.toByte(), 0x2C, packBytes[0], packBytes[1], 0x00, 0x00))
// Set AUTH0 to page 9 (0x09) to protect from page 9 onwards
nfcA.transceive(byteArrayOf(0xA2.toByte(), 0x29, 0x09, 0x00, 0x00, 0x00))
// (Optional) Set PROT bit in page 42 (0x2A) to 1 for read/write protection
nfcA.transceive(byteArrayOf(0xA2.toByte(), 0x2A, 0x80.toByte(), 0x00, 0x00, 0x00))
} catch (e: IOException) {
LogUtil.log(LogUtil.TAG_NFC,"IOException while writing to NFC-A tag -> ${e.message}")
} finally {
try {
nfcA.close()
} catch (e: IOException) {
LogUtil.log(LogUtil.TAG_NFC,"IOException while closing NFC-A tag -> ${e.message}")
}
}
}

fun removePasswordProtection(tag: Tag, password: String) {
val nfcA = NfcA.get(tag)
try {
nfcA.connect()
val passwordBytes = password.toByteArray(Charset.forName("US-ASCII"))
// Authenticate with the current password
nfcA.transceive(byteArrayOf(0x1B, passwordBytes[0], passwordBytes[1], passwordBytes[2], passwordBytes[3]))
val result = nfcA.transceive(byteArrayOf(0x30, 0x29))
// Set AUTH0 to 0xFF to disable password protection
nfcA.transceive(byteArrayOf(0xA2.toByte(), 0x29, result[0], result[1], result[2], 0xFF.toByte()))
} catch (e: IOException) {
LogUtil.log(LogUtil.TAG_NFC, "IOException while writing to NFC-A tag -> ${e.message}")
} finally {
try {
nfcA.close()
} catch (e: IOException) {
LogUtil.log(LogUtil.TAG_NFC,"IOException while closing NFC-A tag -> ${e.message}")
}
}
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post