List of usage examples for javax.smartcardio Card getATR
public abstract ATR getATR();
From source file:davmail.util.ClientCertificateTest.java
public void testCardReaders() throws CardException { for (CardTerminal terminal : TerminalFactory.getDefault().terminals().list()) { System.out.println("Card terminal: " + terminal.getName() + " " + (terminal.isCardPresent() ? "Card present" : "No card")); terminal.waitForCardPresent(10); if (terminal.isCardPresent()) { Card c = null; try { c = terminal.connect("T=0"); } catch (Exception e) { // failover c = terminal.connect("T=1"); }//from w w w. j a v a 2s .co m ATR atr = c.getATR(); byte[] bytes = atr.getBytes(); System.out.print("card:"); for (byte b : bytes) { System.out.print(" " + Integer.toHexString(b & 0xff)); } System.out.println(); } } }
From source file:src.eidreader.EstEIDUtil.java
public String readCard(final Boolean full) { System.err.println("EIDReader.readCard()"); return AccessController.doPrivileged(new PrivilegedAction<String>() { public String run() { try { TerminalFactory factory = TerminalFactory.getDefault(); List<CardTerminal> terminals = factory.terminals().list(); if (terminals.size() == 0) { return "Error: No card reader found"; }/*from ww w. ja v a 2s .co m*/ //~ throws java.lang.IndexOutOfBoundsException when there is no reader CardTerminal terminal = terminals.get(0); if (!terminal.isCardPresent()) { return "Error: No card found on terminal"; //~ return new EidReaderResponse(new String[] { "No card found on terminal" }); } // "The best way to go is, as explained by Shane, to use the wildcard protocol." // https://forums.oracle.com/message/10531935 Card card = terminal.connect("T=0"); // Card card = terminal.connect("T=1"); // Card card = terminal.connect("*"); System.err.println("Protocol: " + card.getProtocol()); ATR atr = card.getATR(); CardChannel channel = card.getBasicChannel(); if (BelgianReader.matchesEidAtr(atr)) { System.err.println("It's a Belgian card"); BelgianReader pf = new BelgianReader(channel); return pf.resultAsString(full); } System.err.println("It's an Estonian card"); PersonalFile pf = new PersonalFile(channel); return pf.resultAsString(full); //~ return new String[] { pf.toString() }; //~ return new EidReaderResponse(pf.getData()); //~ return pf.getSurName(); } catch (Throwable e) { //~ return new EidReaderResponse(new String[] { e.toString() }); e.printStackTrace(); return "Error: " + e.toString(); } } }); }
From source file:test.integ.be.fedict.commons.eid.client.CardAndTerminalManagerExercises.java
@Override public void cardInserted(final CardTerminal cardTerminal, final Card card) { if (card != null) { LOG.debug("Card [" + StringUtils.atrToString(card.getATR()) + "] Inserted Into Terminal [" + cardTerminal.getName() + "]"); } else {/*from ww w . ja v a 2 s. com*/ LOG.debug("Card present but failed to connect()"); } }