本文整理汇总了Java中javax.smartcardio.CardTerminal.connect方法的典型用法代码示例。如果您正苦于以下问题:Java CardTerminal.connect方法的具体用法?Java CardTerminal.connect怎么用?Java CardTerminal.connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.smartcardio.CardTerminal
的用法示例。
在下文中一共展示了CardTerminal.connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testReadPhoto
import javax.smartcardio.CardTerminal; //导入方法依赖的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.CardTerminal; //导入方法依赖的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: connect
import javax.smartcardio.CardTerminal; //导入方法依赖的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;
}
示例4: connect
import javax.smartcardio.CardTerminal; //导入方法依赖的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;
}
示例5: performCommand
import javax.smartcardio.CardTerminal; //导入方法依赖的package包/类
/**
* Method that acquires a CardChannel from the given terminal and performs
* the given GPCommand on it
*
* @param keyset
* @param channelSet
* @param _cmd
* @return
*/
public String performCommand(CardTerminal _term, GPKeyset keyset, GPChannelSet channelSet,
GPCommand _cmd) {
try {
Card c = null;
if (_term instanceof OpenMobileAPITerminal) {
((OpenMobileAPITerminal) _term).setReader(_cmd.getSeekReader());
}
c = _term.connect("*");
System.out.println("Found card in terminal: " + _term.getName());
if (c.getATR() != null) {
System.out.println("ATR: "
+ GPUtil.byteArrayToString(c.getATR().getBytes()));
}
CardChannel channel = c.openLogicalChannel();
return performCommand(channel, keyset, channelSet, _cmd);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例6: main
import javax.smartcardio.CardTerminal; //导入方法依赖的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.");
}
示例7: create
import javax.smartcardio.CardTerminal; //导入方法依赖的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);
}
示例8: waitForCard
import javax.smartcardio.CardTerminal; //导入方法依赖的package包/类
private Card waitForCard(CardTerminals terminals)
throws CardException {
while (true) {
for (CardTerminal ct : terminals
.list(CardTerminals.State.CARD_INSERTION)) {
return ct.connect("*");
}
terminals.waitForChange();
}
}
示例9: getConnectedCardATR
import javax.smartcardio.CardTerminal; //导入方法依赖的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;
}
示例10: main
import javax.smartcardio.CardTerminal; //导入方法依赖的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.");
}
示例11: connectToAllCardsByTerminalFactory
import javax.smartcardio.CardTerminal; //导入方法依赖的package包/类
private static void connectToAllCardsByTerminalFactory(TerminalFactory factory, byte[] appAID, ArrayList<CardChannel> cardsList) throws CardException {
ArrayList<CardTerminal> terminals = new ArrayList<>();
Card card = null;
try {
for (CardTerminal t : factory.terminals().list()) {
terminals.add(t);
if (t.isCardPresent()) {
System.out.print("Connecting...");
card = t.connect("*"); // Connect with the card
System.out.println(" Done.");
System.out.print("Establishing channel...");
CardChannel channel = card.getBasicChannel();
System.out.println(" Done.");
// Select applet (mpcapplet)
System.out.println("Smartcard: Selecting applet...");
CommandAPDU cmd = new CommandAPDU(appAID);
ResponseAPDU response = transmit(channel, cmd);
if (response.getSW() == (ISO7816.SW_NO_ERROR & 0xffff)) {
cardsList.add(channel);
}
}
}
} catch (Exception e) {
System.out.println("Failed.");
}
System.out.println("MPC cards found: " + cardsList.size());
}
示例12: SmartcardTestService
import javax.smartcardio.CardTerminal; //导入方法依赖的package包/类
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");
}
示例13: logoff
import javax.smartcardio.CardTerminal; //导入方法依赖的package包/类
public void logoff(String readerName) throws Exception {
this.view.addDetailMessage("logoff from reader: \"" + readerName + "\"");
TerminalFactory factory = TerminalFactory.getDefault();
CardTerminals cardTerminals = factory.terminals();
CardTerminal cardTerminal = cardTerminals.getTerminal(readerName);
if (null == cardTerminal) {
this.view.addDetailMessage("logoff: card reader not found: " + readerName);
List<String> readerList = getReaderList();
this.view.addDetailMessage("reader list: " + readerList);
// throw new RuntimeException("card reader not found: " +
// readerName);
// we won't fail in this case...
return;
}
Card card = cardTerminal.connect("T=0");
try {
CardChannel cardChannel = card.getBasicChannel();
CommandAPDU logoffApdu = new CommandAPDU(0x80, 0xE6, 0x00, 0x00);
ResponseAPDU responseApdu = cardChannel.transmit(logoffApdu);
this.view.addDetailMessage("logoff... " + readerName);
if (0x9000 != responseApdu.getSW()) {
this.view.addDetailMessage("logoff status word: " + Integer.toHexString(responseApdu.getSW()));
if (0x6e00 == responseApdu.getSW()) {
// BUD001 smart card reader work-around
return;
}
throw new RuntimeException("logoff failed");
}
} finally {
card.disconnect(true);
}
}
示例14: connectTerminal
import javax.smartcardio.CardTerminal; //导入方法依赖的package包/类
@Override
public CardConnection connectTerminal(String name) throws TerminalException {
try {
CardTerminal smartCardIOTerminal = terminals.getTerminal(name);
Card _card = smartCardIOTerminal.connect("*");
return new SmartcardioCardConnection(_card, smartCardIOTerminal);
} catch (CardException ex) {
throw new TerminalException(ex);
}
}
示例15: main
import javax.smartcardio.CardTerminal; //导入方法依赖的package包/类
public static void main(String[] args) {
try {
// show the list of available terminals
TerminalFactory factory = TerminalFactory.getDefault();
List<CardTerminal> terminals = factory.terminals().list();
// get the first terminal
if (terminals.isEmpty()) {
System.out.println("No terminals found!");
} else {
System.out.println("Terminals: " + terminals);
CardTerminal terminal = terminals.get(0);
// establish a connection with the card
// Card card = terminal.connect("T=1");
Card card = terminal.connect("DIRECT");
System.out.println("card: " + card);
byte[] ccidResp = card.transmitControlCommand(
CM_IOCTL_GET_FEATURE_REQUEST, new byte[] {});
System.out.println(HexString.bufferToHex(ccidResp));
CardChannel channel = card.getBasicChannel();
// channel.transmit(new CommandAPDU(new byte[]{0,1,2,3,4,5,6}));
// disconnect
card.disconnect(false);
}
} catch (Exception e) {
System.err.println(e.getLocalizedMessage());
}
}