ESYA Smartcard API uses configuration file in order to
The configuration file is smartcard-config.xml
and distributed within the API package. Initial values are set in this file and these initial values are also embedded in the API source. If no new card configuration exists, then there is no need to use the configuration file.
If the configuration file is modified, then it must be read via SmartCardConfigParser
and the class CardType
must be configured accordingly.
Sample Code: Using the configuration file smartcard-config.xml
.
List<CardTypeConfig> cards = new SmartCardConfigParser().readConfig(); CardType.applyCardTypeConfig(cards);
If the configuration file has different name or it is at some other location then the method which is taking InputStream
of SmartCardConfigParser
can be used.
List<CardTypeConfig> cards = new SmartCardConfigParser().readConfig(inputStream); CardType.applyCardTypeConfig(cards);
A sample card definition is as follows:
<card-type name="AKIS"> <lib name="akisp11"/> <atr value="3BBA11008131FE4D55454B41452056312E30AE"/> <atr value="3B9F968131FE45806755454B41451112318073B3A180E9"/> ... </card-type>
<card-type>
defines the new card type. <lib>
specifies the operationg system specific driver of the card. If 32 bit and 64 bit platforms requires different driver this seperation is indicated as follows:
<card-type name="NCIPHER"> <lib name="cknfast" arch="32"/> <lib name="cknfast-64" arch="64"/>
To detect the card type you need to know the ATR (Answer To Reset) value of the card. As defined in the communication protocol of the card, it sends out a byte sequence when it is reset. If this byte sequence is known and it includes a unique information for a specific card then the card type is detected. For all known ATR sequences there must be an <atr>
element in <card-type>
in the configuration file.
To retrieve ATR value from a card with Java, you can use the code segment below. The code simply prints out the ATR of the smartcard in the first reader.
Card card = TerminalFactory.getDefault().terminals().list().get(0).connect("*"); ATR atr = card.getATR(); String historicalBytesStr = StringUtil.toString(atr.getHistoricalBytes()); System.out.println("historical bytes >"+historicalBytesStr); String atrHex = StringUtil.toString(card.getATR().getBytes()); System.out.println("ATR >"+atrHex);