Reply To: DESFire changeKey Exception

Forum MIFARE SDK DESFire changeKey Exception Reply To: DESFire changeKey Exception

Re: DESFire changeKey Exception

2. December 2015 at 17:23
Hi,

it is very easy to change the for example the Master Key of a DESFire EV1 with the MIFARE SDK Advanced.
Let us assume you extend the example app enclosed with the SDK. There are keys defined:

  /**
* 16 bytes 2KTDES Key.
*/
public static final byte[] KEY_2KTDES = { (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };

public static final byte[] KEY_2KTDES_ALT = { (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff };


The key definition KEY_2KTDES is already defined, KEY_2KTDES_ALT is added from me.
Let us append the keys to the software keystore:

  ks.formatKeyEntry(2, IKeyConstants.KeyType.KEYSTORE_KEY_TYPE_2K3DES);
ks.setKey(2, (byte) 0, IKeyConstants.KeyType.KEYSTORE_KEY_TYPE_2K3DES, KEY_2KTDES);
// ...
ks.formatKeyEntry( 5, IKeyConstants.KeyType.KEYSTORE_KEY_TYPE_2K3DES );
ks.setKey( 5, (byte) 0, IKeyConstants.KeyType.KEYSTORE_KEY_TYPE_2K3DES, KEY_2KTDES_ALT );


Now we can change the key with the SDK. I have changed the method desfireEV1CardLogic() from the sample app:

  //...
objDESFireEV1.connectL4();
objDESFireEV1.authenticate( AuthType.Native, 2, (byte) 0, 0, (byte) 0, null);
objDESFireEV1.setTimeout( 2000 );

showMessage( "Authenticated with key 2", 'd');

objDESFireEV1.changeKey( 0, 2, (byte) 0, 5, (byte) 0, DESFire.KeyType.TWOK3DES,
IKeyConstants.DIV_OPTION_NODIVERSIFICATION,
IKeyConstants.DIV_OPTION_NODIVERSIFICATION, null );
objDESFireEV1.setTimeout( 2000 );

showMessage( "Key changed from 2 to 5", 'd');

objDESFireEV1.authenticate( AuthType.Native, 5, (byte) 0, 0, (byte) 0, null );
objDESFireEV1.setTimeout( 2000 );

showMessage( "Authenticated with key 5", 'd');

objDESFireEV1.closeL4();
//...


This works and does not throw an exception.

It seems that you have a mismatch in your
changeKey()
method. You set
NO_DIVERSIFICATION
but set an diversification input.

Regards,
The MIFARE Team
+ 0  |  - 0