We are trying to change PICC Master key in desfire ev 1 what we currently follow listed under
We are using this key for initial authenthication
val KEY_2TDEA: ByteArray = byteArrayOf(
0x00.toByte(),
0x00.toByte(),
0x00.toByte(),
0x00.toByte(),
0x00.toByte(),
0x00.toByte(),
0x00.toByte(),
0x00.toByte(),
0x00.toByte(),
0x00.toByte(),
0x00.toByte(),
0x00.toByte(),
0x00.toByte(),
0x00.toByte(),
0x00.toByte(),
0x00.toByte(),
0x00.toByte(),
0x00.toByte(),
0x00.toByte(),
0x00.toByte(),
0x00.toByte(),
0x00.toByte(),
0x00.toByte(),
0x00.toByte()
)
We are using this key in change key function to later on authenthicate with this key
val NEW_KEY_2TDEA_BYTES: ByteArray = byteArrayOf(
0x1A, 0x2B, 0x3C, 0x4D, 0x5E, 0x6F, 0x70, 0x81,
0x92, 0xA3, 0xB4, 0xC5, 0xD6, 0xE7, 0xF8, 0x09,
0x10, 0x21, 0x32, 0x43, 0x54, 0x65, 0x76, 0x87
)
What we follow in code !
selectApplicationByIndex(0)desFireEV1.authenticate(
ACCESS_KEY,
IDESFireEV1.AuthType.Native,
KeyType.THREEDES,
objKEY_2TDEA
)
val appsetbuilder = EV1ApplicationKeySettings.Builder()
val appsettings = appsetbuilder.setAppKeySettingsChangeable(
true
).setAppMasterKeyChangeable(true)
.setAuthenticationRequiredForFileManagement(false)
.setAuthenticationRequiredForDirectoryConfigurationData(
false
).setKeyTypeOfApplicationKeys(
KeyType.TWO_KEY_THREEDES
).build()
desFireEV1.createApplication(appAID, appsettings)
selectApplicationByAID(appAID)
desFireEV1.authenticate(
0,
IDESFireEV1.AuthType.Native,
KeyType.TWO_KEY_THREEDES,
objKEY_2TDEA
)
//THIS METHOD CRASHED with this error "com.nxp.nfclib.exceptions.PICCException: Length Error SW2 = 126"
desFireEV1.changeKey(
0,
KeyType.TWO_KEY_THREEDES,
NEW_KEY_2TDEA_BYTES,
KEY_2TDEA,
0x00.toByte()
)
desFireEV1.commitTransaction()
selectApplicationByAID(appAID)
//this will aithenthciate with new key which has been changed after keyChange setting which we understand
desFireEV1.authenticate(
0,
IDESFireEV1.AuthType.Native,
KeyType.TWO_KEY_THREEDES,
newMasterKey
)
NOW my question is why changekey method crash with the define error SW2 = 126
There is a detail steps mentioned in the AN12757 Chapter 6 Key Management.
You could download it in Secure Download Area.