javax.smartcardio.TerminalFactory Java Examples
The following examples show how to use
javax.smartcardio.TerminalFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestDirect.java From jdk8u60 with GNU General Public License v2.0 | 7 votes |
public static void main(String[] args) throws Exception { TerminalFactory terminalFactory = TerminalFactory.getDefault(); List<CardTerminal> cardTerminals = terminalFactory.terminals().list(); System.out.println("Terminals: " + cardTerminals); if (cardTerminals.isEmpty()) { throw new Exception("No card terminals available"); } CardTerminal cardTerminal = cardTerminals.get(0); Card card = cardTerminal.connect("DIRECT"); card.disconnect(true); System.out.println("OK."); }
Example #2
Source File: Utils.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
static CardTerminal getTerminal(String[] args) throws Exception { setLibrary(args); TerminalFactory factory = TerminalFactory.getInstance("PC/SC", null); System.out.println(factory); List<CardTerminal> terminals = factory.terminals().list(); System.out.println("Terminals: " + terminals); if (terminals.isEmpty()) { throw new Exception("No card terminals available"); } CardTerminal terminal = terminals.get(0); if (terminal.isCardPresent() == false) { System.out.println("*** Insert card"); if (terminal.waitForCardPresent(20 * 1000) == false) { throw new Exception("no card available"); } } return terminal; }
Example #3
Source File: Utils.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
static CardTerminal getTerminal(String[] args) throws Exception { setLibrary(args); TerminalFactory factory = TerminalFactory.getInstance("PC/SC", null); System.out.println(factory); List<CardTerminal> terminals = factory.terminals().list(); System.out.println("Terminals: " + terminals); if (terminals.isEmpty()) { throw new Exception("No card terminals available"); } CardTerminal terminal = terminals.get(0); if (terminal.isCardPresent() == false) { System.out.println("*** Insert card"); if (terminal.waitForCardPresent(20 * 1000) == false) { throw new Exception("no card available"); } } return terminal; }
Example #4
Source File: TestDefault.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { TerminalFactory factory = TerminalFactory.getDefault(); System.out.println("Type: " + factory.getType()); List<CardTerminal> terminals = factory.terminals().list(); System.out.println("Terminals: " + terminals); if (terminals.isEmpty()) { throw new Exception("no terminals"); } System.out.println("OK."); }
Example #5
Source File: Utils.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
static CardTerminal getTerminal(String[] args) throws Exception { setLibrary(args); TerminalFactory factory = TerminalFactory.getInstance("PC/SC", null); System.out.println(factory); List<CardTerminal> terminals = factory.terminals().list(); System.out.println("Terminals: " + terminals); if (terminals.isEmpty()) { throw new Exception("No card terminals available"); } CardTerminal terminal = terminals.get(0); if (terminal.isCardPresent() == false) { System.out.println("*** Insert card"); if (terminal.waitForCardPresent(20 * 1000) == false) { throw new Exception("no card available"); } } return terminal; }
Example #6
Source File: TestDefault.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { TerminalFactory factory = TerminalFactory.getDefault(); System.out.println("Type: " + factory.getType()); List<CardTerminal> terminals = factory.terminals().list(); if (terminals.isEmpty()) { System.out.println("Skipping the test: " + "no card terminals available"); return; } System.out.println("Terminals: " + terminals); System.out.println("OK."); }
Example #7
Source File: Utils.java From hottub with GNU General Public License v2.0 | 6 votes |
static CardTerminal getTerminal(String[] args) throws Exception { setLibrary(args); TerminalFactory factory = TerminalFactory.getInstance("PC/SC", null); System.out.println(factory); List<CardTerminal> terminals = factory.terminals().list(); System.out.println("Terminals: " + terminals); if (terminals.isEmpty()) { throw new Exception("No card terminals available"); } CardTerminal terminal = terminals.get(0); if (terminal.isCardPresent() == false) { System.out.println("*** Insert card"); if (terminal.waitForCardPresent(20 * 1000) == false) { throw new Exception("no card available"); } } return terminal; }
Example #8
Source File: SmartcardTestService.java From statelearner with Apache License 2.0 | 6 votes |
public SmartcardTestService() throws Exception { System.setProperty("sun.security.smartcardio.t0GetResponse", "false"); System.setProperty("sun.security.smartcardio.t1GetResponse", "false"); //System.out.println("JRE version: " + System.getProperty("java.version")); //System.out.println("JRE vendor: " + System.getProperty("java.vendor")); //System.out.println("JRE spec version: " + System.getProperty("java.specification.version")); //System.out.println("JRE spec vendor: " + System.getProperty("java.specification.vendor")); // Get list of card readers List<CardTerminal> terminals = TerminalFactory.getDefault().terminals().list(); if(terminals.size() == 0) { throw new Exception("No readers found."); } // Ask user to select a card reader to connect to terminal = (CardTerminal)JOptionPane.showInputDialog(null, "Reader", "Select a reader", JOptionPane.QUESTION_MESSAGE, null, terminals.toArray(), terminals.get(0)); if(terminal == null) { throw new Exception("No reader selected."); } System.err.println("Selected reader: " + terminal.toString()); // Connect to card in selected reader card = terminal.connect("*"); channel = card.getBasicChannel(); System.err.println("Connected to card"); }
Example #9
Source File: TestDirect.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { TerminalFactory terminalFactory = TerminalFactory.getDefault(); List<CardTerminal> cardTerminals = terminalFactory.terminals().list(); System.out.println("Terminals: " + cardTerminals); if (cardTerminals.isEmpty()) { throw new Exception("No card terminals available"); } CardTerminal cardTerminal = cardTerminals.get(0); Card card = cardTerminal.connect("DIRECT"); card.disconnect(true); System.out.println("OK."); }
Example #10
Source File: TestDirect.java From hottub with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { TerminalFactory terminalFactory = TerminalFactory.getDefault(); List<CardTerminal> cardTerminals = terminalFactory.terminals().list(); System.out.println("Terminals: " + cardTerminals); if (cardTerminals.isEmpty()) { throw new Exception("No card terminals available"); } CardTerminal cardTerminal = cardTerminals.get(0); Card card = cardTerminal.connect("DIRECT"); card.disconnect(true); System.out.println("OK."); }
Example #11
Source File: Main.java From openjavacard-ndef with GNU General Public License v3.0 | 5 votes |
public static final void main(String[] arguments) { PrintStream os = System.out; TerminalFactory tf = TerminalFactory.getDefault(); CardTerminals terminals = tf.terminals(); try { // default command is info String command = "info"; // check if user specified a reader as first argument if(arguments.length >= 1) { // if yes then use that reader String terminalName = arguments[0]; CardTerminal terminal = terminals.getTerminal(terminalName); if(terminal == null) { throw new RuntimeException("Could not find terminal \"" + terminalName + "\""); } // check if the user also specified a command if(arguments.length >= 2) { command = arguments[1]; } // split off the command arguments String[] commandArguments = new String[0]; if(arguments.length > 2) { commandArguments = Arrays.copyOfRange(arguments, 2, arguments.length); } // run the command runCommand(terminal, command, commandArguments); } else { // else list all readers os.println("Available terminals:"); for (CardTerminal t : terminals.list()) { os.println(" \"" + t.getName() + "\""); } } } catch (CardException e) { e.printStackTrace(); } }
Example #12
Source File: PhysicalCard.java From OpenPGP-Card with GNU General Public License v3.0 | 5 votes |
public boolean initialize() throws CardException { List<CardTerminal> readersWithCards = TerminalFactory.getDefault().terminals() .list(CardTerminals.State.CARD_PRESENT); if (readersWithCards.isEmpty()) { logger.severe("No card found."); return false; } reader = readersWithCards.get(0); logger.info("Reader: " + reader); card = reader.connect("*"); logger.info("Card: " + card); channel = card.getBasicChannel(); return true; }
Example #13
Source File: TestDefault.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { TerminalFactory factory = TerminalFactory.getDefault(); System.out.println("Type: " + factory.getType()); List<CardTerminal> terminals = factory.terminals().list(); System.out.println("Terminals: " + terminals); if (terminals.isEmpty()) { throw new Exception("no terminals"); } System.out.println("OK."); }
Example #14
Source File: TestDirect.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { TerminalFactory terminalFactory = TerminalFactory.getDefault(); List<CardTerminal> cardTerminals = terminalFactory.terminals().list(); if (cardTerminals.isEmpty()) { System.out.println("Skipping the test: " + "no card terminals available"); return; } System.out.println("Terminals: " + cardTerminals); CardTerminal cardTerminal = cardTerminals.get(0); Card card = cardTerminal.connect("DIRECT"); card.disconnect(true); System.out.println("OK."); }
Example #15
Source File: TestDefault.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { TerminalFactory factory = TerminalFactory.getDefault(); System.out.println("Type: " + factory.getType()); List<CardTerminal> terminals = factory.terminals().list(); System.out.println("Terminals: " + terminals); if (terminals.isEmpty()) { throw new Exception("no terminals"); } System.out.println("OK."); }
Example #16
Source File: TestPresent.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { TerminalFactory factory = TerminalFactory.getInstance("PC/SC", null); System.out.println(factory); List<CardTerminal> terminals = factory.terminals().list(); System.out.println("Terminals: " + terminals); if (terminals.isEmpty()) { throw new Exception("No card terminals available"); } CardTerminal terminal = terminals.get(0); while (terminal.isCardPresent()) { System.out.println("*** Remove card!"); Thread.sleep(1000); } Timer timer = new Timer(); System.out.println("Testing waitForCardAbsent() with card already absent..."); isTrue(terminal.waitForCardAbsent(10)); timer.print(); isTrue(terminal.waitForCardAbsent(100)); timer.print(); isTrue(terminal.waitForCardAbsent(10000)); timer.print(); isTrue(terminal.waitForCardAbsent(0)); timer.print(); System.out.println("Testing waitForCardPresent() timeout..."); isFalse(terminal.waitForCardPresent(10)); timer.print(); isFalse(terminal.waitForCardPresent(100)); timer.print(); isFalse(terminal.waitForCardPresent(1000)); timer.print(); isFalse(terminal.isCardPresent()); isFalse(terminal.isCardPresent()); System.out.println("*** Insert card!"); isTrue(terminal.waitForCardPresent(0)); timer.print(); isTrue(terminal.isCardPresent()); isTrue(terminal.isCardPresent()); System.out.println("Testing waitForCardPresent() with card already present..."); isTrue(terminal.waitForCardPresent(0)); timer.print(); isTrue(terminal.waitForCardPresent(10000)); timer.print(); isTrue(terminal.waitForCardPresent(100)); timer.print(); isTrue(terminal.waitForCardPresent(10)); timer.print(); System.out.println("Testing waitForCardAbsent() timeout..."); isFalse(terminal.waitForCardAbsent(1000)); timer.print(); isFalse(terminal.waitForCardAbsent(100)); timer.print(); isFalse(terminal.waitForCardAbsent(10)); timer.print(); System.out.println("*** Remove card!"); isTrue(terminal.waitForCardAbsent(0)); timer.print(); isFalse(terminal.isCardPresent()); isFalse(terminal.isCardPresent()); System.out.println("OK."); }
Example #17
Source File: TestDirect.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { TerminalFactory terminalFactory = TerminalFactory.getDefault(); List<CardTerminal> cardTerminals = terminalFactory.terminals().list(); System.out.println("Terminals: " + cardTerminals); if (cardTerminals.isEmpty()) { throw new Exception("No card terminals available"); } CardTerminal cardTerminal = cardTerminals.get(0); Card card = cardTerminal.connect("DIRECT"); card.disconnect(true); System.out.println("OK."); }
Example #18
Source File: Utils.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
static TerminalFactory getTerminalFactory(String provName) throws Exception { try { TerminalFactory factory = (provName == null) ? TerminalFactory.getInstance("PC/SC", null) : TerminalFactory.getInstance("PC/SC", null, provName); System.out.println(factory); return factory; } catch (NoSuchAlgorithmException e) { Throwable cause = e.getCause(); if (cause != null && cause.getMessage().startsWith("PC/SC not available")) { return null; } throw e; } }
Example #19
Source File: TerminalFactorySpiTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { Provider myProvider = new MyProvider(); Security.addProvider(myProvider); System.out.println(Arrays.asList(Security.getProviders())); TerminalFactory.getInstance("MyType", new Object()).terminals(); if (!callMethod) { throw new RuntimeException("Expected engineTerminals() not called"); } }
Example #20
Source File: TerminalFactorySpiTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { Provider myProvider = new MyProvider(); Security.addProvider(myProvider); System.out.println(Arrays.asList(Security.getProviders())); TerminalFactory.getInstance("MyType", new Object()).terminals(); if (!callMethod) { throw new RuntimeException("Expected engineTerminals() not called"); } }
Example #21
Source File: Utils.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
static CardTerminal getTerminal(String[] args, String provider) throws Exception { setLibrary(args); try { TerminalFactory factory = (provider == null) ? TerminalFactory.getInstance("PC/SC", null) : TerminalFactory.getInstance("PC/SC", null, provider); System.out.println(factory); List<CardTerminal> terminals = factory.terminals().list(); System.out.println("Terminals: " + terminals); if (terminals.isEmpty()) { return null; } CardTerminal terminal = terminals.get(0); if (terminal.isCardPresent() == false) { System.out.println("*** Insert card"); if (terminal.waitForCardPresent(20 * 1000) == false) { throw new Exception("no card available"); } } System.out.println("card present: " + terminal.isCardPresent()); return terminal; } catch (NoSuchAlgorithmException e) { Throwable cause = e.getCause(); if (cause != null && cause.getMessage().startsWith("PC/SC not available")) { return null; } throw e; } }
Example #22
Source File: Utils.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
static TerminalFactory getTerminalFactory(String provName) throws Exception { try { TerminalFactory factory = (provName == null) ? TerminalFactory.getInstance("PC/SC", null) : TerminalFactory.getInstance("PC/SC", null, provName); System.out.println(factory); return factory; } catch (NoSuchAlgorithmException e) { Throwable cause = e.getCause(); if (cause != null && cause.getMessage().startsWith("PC/SC not available")) { return null; } throw e; } }
Example #23
Source File: TestDefault.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { TerminalFactory factory = TerminalFactory.getDefault(); System.out.println("Type: " + factory.getType()); List<CardTerminal> terminals = factory.terminals().list(); if (terminals.isEmpty()) { System.out.println("Skipping the test: " + "no card terminals available"); return; } System.out.println("Terminals: " + terminals); System.out.println("OK."); }
Example #24
Source File: TestDirect.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { TerminalFactory terminalFactory = TerminalFactory.getDefault(); List<CardTerminal> cardTerminals = terminalFactory.terminals().list(); if (cardTerminals.isEmpty()) { System.out.println("Skipping the test: " + "no card terminals available"); return; } System.out.println("Terminals: " + cardTerminals); CardTerminal cardTerminal = cardTerminals.get(0); Card card = cardTerminal.connect("DIRECT"); card.disconnect(true); System.out.println("OK."); }
Example #25
Source File: TerminalFactorySpiTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { Provider myProvider = new MyProvider(); Security.addProvider(myProvider); System.out.println(Arrays.asList(Security.getProviders())); TerminalFactory.getInstance("MyType", new Object()).terminals(); if (!callMethod) { throw new RuntimeException("Expected engineTerminals() not called"); } }
Example #26
Source File: Utils.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
static CardTerminal getTerminal(String[] args, String provider) throws Exception { setLibrary(args); try { TerminalFactory factory = (provider == null) ? TerminalFactory.getInstance("PC/SC", null) : TerminalFactory.getInstance("PC/SC", null, provider); System.out.println(factory); List<CardTerminal> terminals = factory.terminals().list(); System.out.println("Terminals: " + terminals); if (terminals.isEmpty()) { return null; } CardTerminal terminal = terminals.get(0); if (terminal.isCardPresent() == false) { System.out.println("*** Insert card"); if (terminal.waitForCardPresent(20 * 1000) == false) { throw new Exception("no card available"); } } System.out.println("card present: " + terminal.isCardPresent()); return terminal; } catch (NoSuchAlgorithmException e) { Throwable cause = e.getCause(); if (cause != null && cause.getMessage().startsWith("PC/SC not available")) { return null; } throw e; } }
Example #27
Source File: Utils.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
static TerminalFactory getTerminalFactory(String provName) throws Exception { try { TerminalFactory factory = (provName == null) ? TerminalFactory.getInstance("PC/SC", null) : TerminalFactory.getInstance("PC/SC", null, provName); System.out.println(factory); return factory; } catch (NoSuchAlgorithmException e) { Throwable cause = e.getCause(); if (cause != null && cause.getMessage().startsWith("PC/SC not available")) { return null; } throw e; } }
Example #28
Source File: TestDefault.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { TerminalFactory factory = TerminalFactory.getDefault(); System.out.println("Type: " + factory.getType()); List<CardTerminal> terminals = factory.terminals().list(); if (terminals.isEmpty()) { System.out.println("Skipping the test: " + "no card terminals available"); return; } System.out.println("Terminals: " + terminals); System.out.println("OK."); }
Example #29
Source File: TestDirect.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { TerminalFactory terminalFactory = TerminalFactory.getDefault(); List<CardTerminal> cardTerminals = terminalFactory.terminals().list(); if (cardTerminals.isEmpty()) { System.out.println("Skipping the test: " + "no card terminals available"); return; } System.out.println("Terminals: " + cardTerminals); CardTerminal cardTerminal = cardTerminals.get(0); Card card = cardTerminal.connect("DIRECT"); card.disconnect(true); System.out.println("OK."); }
Example #30
Source File: Utils.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
static TerminalFactory getTerminalFactory(String provName) throws Exception { try { TerminalFactory factory = (provName == null) ? TerminalFactory.getInstance("PC/SC", null) : TerminalFactory.getInstance("PC/SC", null, provName); System.out.println(factory); return factory; } catch (NoSuchAlgorithmException e) { Throwable cause = e.getCause(); if (cause != null && cause.getMessage().startsWith("PC/SC not available")) { return null; } throw e; } }