Problem
Im working at a company where there is an application where guests have to register using their Belgian ID, this is a smartcard containing data to the person(name, age, sex,...). But it reads certain characters wrong: é, ç,... I have figured out that this is a problem between the library that is reading the ID and the java-program. The library must read the strings in a different encoding or no incoding en when they get placed in a java-application the strings are being read incorrectly.
Attempts
I have tried before the string gets displayed to catch it, look for incorrect characters and transform them back into the correct ones. ex: search for ç and replace it with ç. But this doesn't seem to work. I have also tried upgrading the library and downgrading it to see if it would make a difference but these same reading errors persist. The library used to read the ID's is commens-eid.
Reading eID code
This is the code that reads the eID, this code works for every version of the eID except when the name contains a special character like: é, ù, ... The string that is then retrieved gets placed in a javafx textfield. But as java is encoded in utf-16 (or something like it) it seems highly unlikely that the problem occurs when placing the text in the textfield. The library used is commens-eid.
System.out.println("card connected.");
BeIDCards beIDCards = new BeIDCards();
try {
final BeIDCard beIDCard = beIDCards.getOneBeIDCard();
System.out.println("reading identity file");
final byte[] identityFile = beIDCard.readFile(FileType.Identity);
final Identity identity = TlvParser.parse(identityFile,
Identity.class);
final String firstName = StringUtilities.format(identity.firstName);
final String lastName = identity.name;
//geslacht selecteren.
Platform.runLater(new Runnable() {
@Override
public void run() {
int index = 0;
switch (identity.gender) {
case MALE:
index = 1;
break;
case FEMALE:
index = 2;
break;
default:
index = 3;
break;
}
//zorgt evoor dat de volledige node weergegeven wordt en niet een deel.
cbTitle.getSelectionModel().select(index);
laadcirkel.setVisible(false);
txtFirstName.setText(firstName);
txtLastName.setText(lastName);
txtFirstName.autosize();
txtLastName.autosize();
}
});
if (beIDCards.getAllBeIDCards().contains(beIDCard)) {
System.out.println("waiting for card removal");
beIDCards.waitUntilCardRemoved(beIDCard);
}
System.out.println("card removed");
} catch (final CancelledException cex) {
System.out.println("Cancelled By User");
} catch (CardException ex) {
Logger.getLogger(AanmeldPagina.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(AanmeldPagina.class.getName()).log(Level.SEVERE, null, ex);
} catch (InterruptedException ex) {
Logger.getLogger(AanmeldPagina.class.getName()).log(Level.SEVERE, null, ex);
}