本文整理汇总了Java中javax.smartcardio.TerminalFactory类的典型用法代码示例。如果您正苦于以下问题:Java TerminalFactory类的具体用法?Java TerminalFactory怎么用?Java TerminalFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TerminalFactory类属于javax.smartcardio包,在下文中一共展示了TerminalFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testReadPhoto
import javax.smartcardio.TerminalFactory; //导入依赖的package包/类
@Test
public void testReadPhoto() throws Exception {
TerminalFactory terminalFactory = TerminalFactory.getDefault();
CardTerminals cardTerminals = terminalFactory.terminals();
CardTerminal cardTerminal = cardTerminals.list().get(0);
Card card = cardTerminal.connect("T=0");
CardChannel cardChannel = card.getBasicChannel();
// select file
cardChannel.transmit(
new CommandAPDU(0x00, 0xA4, 0x08, 0x0C, new byte[] { 0x3F, 0x00, (byte) 0xDF, 0x01, 0x40, 0x35 }));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int offset = 0;
ResponseAPDU responseApdu;
do {
// read binary
responseApdu = cardChannel.transmit(new CommandAPDU(0x00, 0xB0, offset >> 8, offset & 0xFF, 0xff));
baos.write(responseApdu.getData());
offset += responseApdu.getData().length;
} while (responseApdu.getData().length == 0xff);
BufferedImage photo = ImageIO.read(new ByteArrayInputStream(baos.toByteArray()));
JOptionPane.showMessageDialog(null, new ImageIcon(photo));
}
示例2: main
import javax.smartcardio.TerminalFactory; //导入依赖的package包/类
public static void main(final String[] args) throws CardException, CommunicationException {
TerminalFactory factory = TerminalFactory.getDefault();
List<CardTerminal> terminals = factory.terminals().list();
LOGGER.info("Terminals: " + terminals);
if (terminals != null && !terminals.isEmpty()) {
// Use the first terminal
CardTerminal terminal = terminals.get(0);
// Connect with the card
Card card = terminal.connect("*");
LOGGER.info("card: " + card);
CardChannel channel = card.getBasicChannel();
PcscProvider provider = new PcscProvider(channel);
EmvParser parser = new EmvParser(provider, false);
parser.readEmvCard();
// Disconnect the card
card.disconnect(false);
} else {
LOGGER.error("No pcsc terminal found");
}
}
示例3: main
import javax.smartcardio.TerminalFactory; //导入依赖的package包/类
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");
}
}
示例4: connect
import javax.smartcardio.TerminalFactory; //导入依赖的package包/类
/**
* Establishes a connection with a card. The first reader found is used.
*
* @return <code>true</code> on success
*/
public boolean connect(int termNb) {
CardTerminals cardTerminals = TerminalFactory.getDefault().terminals();
try {
CardTerminal terminal = cardTerminals.list().get(termNb);
if (!terminal.isCardPresent()) {
System.out.println("No smart card present on the terminal.");
return false;
}
card = terminal.connect("*");
channel = card.getBasicChannel();
System.out.println(channel.getCard().toString());
} catch (CardException e) {
e.printStackTrace();
System.out.println("Is reader connected?");
return false;
}
return true;
}
示例5: connect
import javax.smartcardio.TerminalFactory; //导入依赖的package包/类
/**
* Establish connection to terminal and card on terminal.
*
* @param index
* Number of the terminal to use
* @return connect Connection successfull ?
* @throws CardException
*/
public boolean connect(int index) throws CardException {
/* Is a Reader connected we can access? */
if (TerminalFactory.getDefault().terminals().list().size() == 0) {
logger.error("No reader available");
throw new CardException("No reader available");
}
/* Terminal we are working on */
CardTerminal terminal = TerminalFactory.getDefault().terminals().list().get(index);
/* Is a card present? */
if (!terminal.isCardPresent()) {
logger.error("No card available");
throw new CardException("No card available");
}
card = terminal.connect("T=1");
channel = card.getBasicChannel();
connected = true;
return connected;
}
示例6: CardAndTerminalManager
import javax.smartcardio.TerminalFactory; //导入依赖的package包/类
/**
* Instantiate a CardAndTerminalManager working on a specific CardTerminals
* instance, and that logs to the given Logger.In normal operation, you
* would use the constructor that takes no CardTerminals parameter, but
* using this one you could, for example obtain a CardTerminals instance
* from a different TerminalFactory, or from your own implementation.
*
* @param logger
* an instance of be.fedict.commons.eid.spi.Logger that will be
* send all the logs
* @param cardTerminals
* instance to obtain terminal and card events from
*/
public CardAndTerminalManager(final Logger logger,
final CardTerminals cardTerminals) {
// work around implementation bug in some GNU/Linux JRE's that causes
// libpcsc not to be found.
LibJ2PCSCGNULinuxFix.fixNativeLibrary(logger);
this.cardTerminalEventsListeners = new HashSet<CardTerminalEventsListener>();
this.cardEventsListeners = new HashSet<CardEventsListener>();
this.terminalsToIgnoreCardEventsFor = new HashSet<String>();
this.delay = DEFAULT_DELAY;
this.logger = logger;
this.running = false;
this.subSystemInitialized = false;
this.autoconnect = true;
this.protocol = PROTOCOL.ANY;
if (cardTerminals == null) {
final TerminalFactory terminalFactory = TerminalFactory
.getDefault();
this.cardTerminals = terminalFactory.terminals();
} else {
this.cardTerminals = cardTerminals;
}
}
示例7: getTerminal
import javax.smartcardio.TerminalFactory; //导入依赖的package包/类
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;
}
示例8: main
import javax.smartcardio.TerminalFactory; //导入依赖的package包/类
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.");
}
示例9: run
import javax.smartcardio.TerminalFactory; //导入依赖的package包/类
public void run() throws Exception {
Security.insertProviderAt(new SmartcardioProvider(), 1);
//
// use "getInstance" to provide more detailed access
// TerminalFactory factory = TerminalFactory.getInstance("PC/SC", null);
TerminalFactory factory = TerminalFactory.getDefault();
CardTerminals terminals = factory.terminals();
List<CardTerminal> list = terminals.list();
for (CardTerminal terminal : list) {
System.out.println("found " + terminal + " named "
+ terminal.getName());
}
}
示例10: run
import javax.smartcardio.TerminalFactory; //导入依赖的package包/类
public void run() throws Exception {
Security.insertProviderAt(new SmartcardioProvider(), 1);
//
TerminalFactory factory = TerminalFactory.getDefault();
CardTerminals terminals = factory.terminals();
while (System.in.available() == 0) {
List<CardTerminal> list = terminals.list(State.CARD_INSERTION);
if (list.isEmpty()) {
System.out.println("no terminals");
}
for (CardTerminal cardTerminal : list) {
try {
connect(cardTerminal);
} catch (Exception e) {
System.out.println("error connecting " + e);
}
}
System.out.println("wait for change");
if (terminals.waitForChange(1000)) {
System.out.println("change detected...");
} else {
System.out.println("timeout");
}
}
}
示例11: main
import javax.smartcardio.TerminalFactory; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
TerminalFactory context;
CardTerminals terminals;
if (true) {
Security.addProvider(new Smartcardio());
context = TerminalFactory.getInstance("PC/SC", null, Smartcardio.PROVIDER_NAME);
terminals = context.terminals();
} else {
TerminalFactory terminalFactory = TerminalFactory.getDefault();
terminals = terminalFactory.terminals();
}
List<CardTerminal> present = terminals.list(State.CARD_PRESENT);
List<CardTerminal> absent = terminals.list(State.CARD_ABSENT);
System.out.format("Initial: cards are present in %s; cards are absent from %s%n", terminalNames(present), terminalNames(absent));
while (true) {
terminals.waitForChange();
List<CardTerminal> inserted = terminals.list(State.CARD_INSERTION);
List<CardTerminal> removed = terminals.list(State.CARD_REMOVAL);
System.out.format("Card inserted in %s; cards removed from %s%n", terminalNames(inserted), terminalNames(removed));
}
}
示例12: create
import javax.smartcardio.TerminalFactory; //导入依赖的package包/类
public static SmartcardIoTransmitter create() throws CardException {
TerminalFactory tf = TerminalFactory.getDefault();
CardTerminal cardTerminal = null;
if (tf.terminals().list().size() == 1) {
cardTerminal = tf.terminals().list().get(0);
} else {
for (CardTerminal terminal : tf.terminals().list()) {
logger.info("Checking for card: {}", terminal.getName());
if (terminal.isCardPresent()) {
cardTerminal = terminal;
}
}
}
if (cardTerminal != null) {
cardTerminal.waitForCardPresent(0);
} else {
throw new RuntimeException("No card found!");
}
logger.info("Using -> " + cardTerminal.getName());
Card card = cardTerminal.connect("*");
return new SmartcardIoTransmitter(card);
}
示例13: getConnectedCardATR
import javax.smartcardio.TerminalFactory; //导入依赖的package包/类
public static ArrayList<String> getConnectedCardATR(){
ArrayList<String> ret = new ArrayList<String>();
try{
List<CardTerminal> terminalList = TerminalFactory.getDefault().terminals().list();
for(CardTerminal terminal:terminalList)
if(terminal.isCardPresent()){
javax.smartcardio.Card card = terminal.connect("*");
ret.add(StringUtils.toHexString(card.getATR().getBytes()));
card.disconnect(false);
}
}catch(Exception ex){}
return ret;
}
示例14: main
import javax.smartcardio.TerminalFactory; //导入依赖的package包/类
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.");
}
示例15: main
import javax.smartcardio.TerminalFactory; //导入依赖的package包/类
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.");
}