Forum Replies Created
-
"data" is "dataToWrite" that already converted to byte
+ 0 | - 0
Data 1 : {“idUserMember":"401137b69416cc031f5431561","firstName":"Amrita","lastName":"Thapa","pinCode":"123456","busRouteName":"lakeside-bagar","busNumber":"GA 1 KHA 4452","idRoute":"37384429c8d2732d5152e025","role":"driver","idc":"123456789012345678905555","receiptHeader1":company,"receiptHeader2":NFC,"receiptHeader3":city,"umid":1234567890123,"wid":1234567890123,"fareType":"2 5 "}
Data 2 : 401137b69416cc031f5431561;123456;37384429c8d2732d5152e025;123456789012345678905555
Data 1 sometimes showing Invalid MAC error
Data 2 always successfully write to the card
+ 0 | - 0
EV1ApplicationKeySettings.Builder appSetBuilder = new EV1ApplicationKeySettings.Builder();
EV1ApplicationKeySettings appSettings = appSetBuilder
.setAppKeySettingsChangeable(true)
.setAppMasterKeyChangeable(true)
.setAuthenticationRequiredForFileManagement(false)
.setAuthenticationRequiredForDirectoryConfigurationData(false)
.setKeyTypeOfApplicationKeys(KeyType.AES128)
.build();
desFireEV1.createApplication(appId, appSettings);
desFireEV1.selectApplication(appId);
Key oldKey = new SecretKeySpec(SampleAppKeys.KEY_AES128_ZEROS,"AES");
KeyData oldKeyData = new KeyData();
oldKeyData.setKey(oldKey);
desFireEV1.authenticate(0, IDESFireEV1.AuthType.AES, KeyType.AES128, oldKeyData);
desFireEV1.createFile(fileNo, new DESFireFile.StdDataFileSettings(
IDESFireEV1.CommunicationType.MACed, (byte) 0, (byte) 0, (byte) 0, (byte) 0, fileSize));
Log.e("a",dataToWrite);
desFireEV1.writeData(0, 0, data,IDESFireEV1.CommunicationType.Echipered);
desFireEV1.changeKey(0,KeyType.AES128,SampleAppKeys.KEY_AES128_ZEROS,SampleAppKeys.KEY_AES128,(byte)0);
this is my code, error happened ad writeData function
+ 0 | - 0
i try to use
desFireEV1.credit(0, 10);
desFireEV1.commitTransaction();
but found error in the picture..
how to do credit or debit?
+ 0 | - 0
the case is i need to read the card first to know the data in the card, then write it again with new data..
what I suppose to do? this is my full code
private void DESFireLogic(final IDESFireEV1 desFireEV1, Intent intent){
try{
final Tag detectedTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
byte[] appId = new byte[]{0x12, 0x00, 0x00};
int fileSize = 100;
int fileNo = 0;
ch1 = bin2hex(detectedTag.getId()).charAt(0);
ch2 = bin2hex(detectedTag.getId()).charAt(2);
ch3 = bin2hex(detectedTag.getId()).charAt(13);
ch4 = bin2hex(detectedTag.getId()).charAt(6);
key = ch1+""+ch2+""+ch3+""+ch4;
desFireEV1.getReader().connect();
desFireEV1.getReader().setTimeout(2000);
desFireEV1.selectApplication(0);
desFireEV1.authenticate(0, IDESFireEV1.AuthType.Native, KeyType.THREEDES, objKEY_2KTDES);
desFireEV1.selectApplication(appId);
desFireEV1.authenticate(0, IDESFireEV1.AuthType.Native, KeyType.TWO_KEY_THREEDES, objKEY_2KTDES);
byte[] data = desFireEV1.readData(0,0,100);
String result = new String(data);
Log.e("s",result);
String decrypt = encryptDecrypt(result,key);
String[] split = decrypt.split(":");
crc32.reset();
crc32.update(decrypt.getBytes());
if(split.length == 2){
String[] splitAgain = split[1].split(";");
Log.e("s", String.valueOf(splitAgain.length));
if(splitAgain.length == 4){
double balance = Double.parseDouble(splitAgain[2]);
double totalAmount = p.getQuantity() + Double.parseDouble(p.getPrice());
if(balance >= totalAmount){
double newBalance = balance - totalAmount;
String dataOne = splitAgain[0];
String dataTwo = splitAgain[1];
String newDataThree = addString(String.valueOf(newBalance));
dataToWrite = dataOne+";"+dataTwo+";"+newDataThree+";";
crc32.reset();
crc32.update(dataToWrite.getBytes());
String encryptOne = encryptDecrypt(crc32.getValue()+":"+dataToWrite,key);
newData = encryptOne.getBytes();
try{
desFireEV1.writeData(0, 0, newData);
}catch (Exception e) {
e.printStackTrace();
}
} else {
popupFailed("Balance not ");
}
}else{
Log.e("s","here1");
popupError();
}
}else{
Log.e("s","here3");
popupError();
}
desFireEV1.getReader().close();
String path = Environment.getExternalStorageDirectory().getPath() + File.separator + "DESFireLogs";
NxpLogUtils.setLogFilePath(path);
NxpLogUtils.save();
}catch (Exception e) {
e.printStackTrace();
}
}
+ 0 | - 0
Re: Reply To: com.nxp.nfclib.exceptions.InvalidResponseLengthException: Integrity Error
3. April 2020 at 9:48 in reply to: com.nxp.nfclib.exceptions.InvalidResponseLengthException: Integrity ErrorI try to do something like this
EV1ApplicationKeySettings.Builder appSetBuilder = new EV1ApplicationKeySettings.Builder();
EV1ApplicationKeySettings appSettings = appSetBuilder
.setAppKeySettingsChangeable(true)
.setAppMasterKeyChangeable(true)
.setAuthenticationRequiredForFileManagement(false)
.setAuthenticationRequiredForDirectoryConfigurationData(false)
.setKeyTypeOfApplicationKeys(KeyType.AES128)
.build();
desFireEV1.createApplication(appId, appSettings);
desFireEV1.selectApplication(appId);
desFireEV1.createFile(fileNo, new DESFireFile.StdDataFileSettings(
IDESFireEV1.CommunicationType.Enciphered, (byte) 0, (byte) 0, (byte) 0, (byte) 0, fileSize));
Key newKey = new SecretKeySpec(SampleAppKeys.KEY_AES128,"AES");
KeyData newKeyData = new KeyData();
newKeyData.setKey(newKey);
desFireEV1.authenticate(0, IDESFireEV1.AuthType.AES, KeyType.AES128, newKeyData);
desFireEV1.writeData(0, 0, data,IDESFireEV1.CommunicationType.Enciphered);
but I got Authentication Error
+ 0 | - 0
Re: Reply To: com.nxp.nfclib.exceptions.InvalidResponseLengthException: Integrity Error
2. April 2020 at 3:34 in reply to: com.nxp.nfclib.exceptions.InvalidResponseLengthException: Integrity Errorwhat is chiper?? where i can set it? if I try to access EV1ApplicationKeySettings object I can't find chiper...
+ 0 | - 0
-
AuthorPosts
Viewing 7 posts - 1 through 7 (of 7 total)