本文整理汇总了Java中javax.smartcardio.Card.getBasicChannel方法的典型用法代码示例。如果您正苦于以下问题:Java Card.getBasicChannel方法的具体用法?Java Card.getBasicChannel怎么用?Java Card.getBasicChannel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.smartcardio.Card
的用法示例。
在下文中一共展示了Card.getBasicChannel方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testReadPhoto
import javax.smartcardio.Card; //导入方法依赖的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.Card; //导入方法依赖的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: connectToAllCardsByTerminalFactory
import javax.smartcardio.Card; //导入方法依赖的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());
}
示例4: logoff
import javax.smartcardio.Card; //导入方法依赖的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);
}
}
示例5: main
import javax.smartcardio.Card; //导入方法依赖的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());
}
}
示例6: any
import javax.smartcardio.Card; //导入方法依赖的package包/类
public static CardDelegate any(boolean sign, NotificationInterface console) throws CardException {
CardTerminal t = EstEID.getTerminal();
if (t == null) {
return null;
}
t = LoggingCardTerminal.getInstance(t);
Card c = t.connect("*");
return new CardDelegate(c.getBasicChannel(), sign, console == null ? CONSOLE : console);
}
示例7: testTransmit
import javax.smartcardio.Card; //导入方法依赖的package包/类
@Test public void testTransmit() throws CardException {
List<CardTerminal> terminalList = terminals.list();
CardTerminal terminal = terminalList.get(0);
Card connection = terminal.connect("*");
CardChannel channel = connection.getBasicChannel();
assertEquals(0, channel.getChannelNumber());
ResponseAPDU response = channel.transmit(new CommandAPDU(0x00, 0xa4, 0x00, 0x00, 0));
int sw = response.getSW();
assertEquals(String.format("got response 0x%04x instead of 0x9000, %s", sw, response), 0x9000, sw);
}
示例8: connectToCardByTerminalFactory
import javax.smartcardio.Card; //导入方法依赖的package包/类
private CardChannel connectToCardByTerminalFactory(TerminalFactory factory, int targetReaderIndex) throws CardException {
List<CardTerminal> terminals = new ArrayList<>();
boolean card_found = false;
CardTerminal terminal = null;
Card card = null;
try {
for (CardTerminal t : factory.terminals().list()) {
terminals.add(t);
if (t.isCardPresent()) {
card_found = true;
}
}
System.out.println("Success.");
} catch (Exception e) {
System.out.println("Failed.");
}
if (card_found) {
System.out.println("Cards found: " + terminals);
terminal = terminals.get(targetReaderIndex); // Prioritize physical card over simulations
System.out.print("Connecting...");
card = terminal.connect("*"); // Connect with the card
System.out.println(" Done.");
System.out.print("Establishing channel...");
m_channel = card.getBasicChannel();
System.out.println(" Done.");
// Select applet (mpcapplet)
System.out.println("Smartcard: Selecting applet...");
CommandAPDU cmd = new CommandAPDU(0x00, 0xa4, 0x04, 0x00, m_APPLET_AID);
ResponseAPDU response = transmit(cmd);
} else {
System.out.print("Failed to find physical card.");
}
if (card != null) {
return card.getBasicChannel();
} else {
return null;
}
}
示例9: connectToCardByTerminalFactory
import javax.smartcardio.Card; //导入方法依赖的package包/类
private CardChannel connectToCardByTerminalFactory(TerminalFactory factory, int targetReaderIndex) throws CardException {
List<CardTerminal> terminals = new ArrayList<>();
boolean card_found = false;
CardTerminal terminal = null;
Card card = null;
try {
for (CardTerminal t : factory.terminals().list()) {
terminals.add(t);
if (t.isCardPresent()) {
card_found = true;
}
}
} catch (Exception ignored) {
}
if (card_found) {
System.out.println("Cards found: " + terminals);
terminal = terminals.get(targetReaderIndex);
System.out.print("Connecting...");
card = terminal.connect("*");
System.out.println(" done.");
System.out.print("Establishing channel...");
m_channel = card.getBasicChannel();
System.out.println(" done.");
System.out.print("Selecting applet...");
CommandAPDU cmd = new CommandAPDU(0x00, 0xa4, 0x04, 0x00, m_APPLET_AID);
ResponseAPDU response = transmit(cmd);
if (response.getSW() == (ISO7816.SW_NO_ERROR & 0xffff)) {
System.out.print(" done");
}
else {
System.out.print(" failed.");
}
} else {
System.out.print("Failed to find required card.");
}
if (card != null) {
return card.getBasicChannel();
} else {
return null;
}
}
示例10: main
import javax.smartcardio.Card; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
CardTerminal terminal = getTerminal(args);
if (terminal == null) {
System.out.println("Skipping the test: " +
"no card terminals available");
return;
}
Card card = terminal.connect("T=0");
CardChannel channel = card.getBasicChannel();
BufferedReader reader = new BufferedReader(new FileReader("apdu.log"));
byte[] command = null;
while (true) {
String line = reader.readLine();
if (line == null) {
break;
}
if (line.startsWith(CMD_MARKER)) {
System.out.println(line);
line = line.substring(CMD_MARKER.length());
command = parse(line);
} else if (line.startsWith(RES_MARKER)) {
System.out.println(line);
line = line.substring(RES_MARKER.length());
Bytes response = parseWildcard(line);
CommandAPDU capdu = new CommandAPDU(command);
ResponseAPDU rapdu = channel.transmit(capdu);
byte[] received = rapdu.getBytes();
if (received.length != response.bytes.length) {
throw new Exception("Length mismatch: " + toString(received));
}
for (int i = 0; i < received.length; i++) {
byte mask = response.mask[i];
if ((received[i] & response.mask[i]) != response.bytes[i]) {
throw new Exception("Mismatch: " + toString(received));
}
}
} // else ignore
}
// disconnect
card.disconnect(true);
System.out.println("OK.");
}
示例11: transmit
import javax.smartcardio.Card; //导入方法依赖的package包/类
private static void transmit(Card card) throws Exception {
CardChannel channel = card.getBasicChannel();
System.out.println("Transmitting...");
transmitTestCommand(channel);
}
示例12: connectToCardByTerminalFactory
import javax.smartcardio.Card; //导入方法依赖的package包/类
private static CardChannel connectToCardByTerminalFactory(TerminalFactory factory, int targetReaderIndex, byte[] appAID) throws CardException {
ArrayList<CardTerminal> terminals = new ArrayList<>();
boolean card_found = false;
CardTerminal terminal = null;
Card card = null;
try {
for (CardTerminal t : factory.terminals().list()) {
terminals.add(t);
if (t.isCardPresent()) {
card_found = true;
}
}
System.out.println("Success.");
} catch (Exception e) {
System.out.println("Failed.");
}
if (card_found) {
System.out.println("Cards found: " + terminals);
terminal = terminals.get(targetReaderIndex); // Prioritize physical card over simulations
System.out.print("Connecting...");
card = terminal.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);
} else {
System.out.print("Failed to find physical card.");
}
if (card != null) {
return card.getBasicChannel();
} else {
return null;
}
}
示例13: main
import javax.smartcardio.Card; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
CardTerminal terminal = getTerminal(args);
Card card = terminal.connect("T=0");
CardChannel channel = card.getBasicChannel();
BufferedReader reader = new BufferedReader(new FileReader("apdu.log"));
byte[] command = null;
while (true) {
String line = reader.readLine();
if (line == null) {
break;
}
if (line.startsWith(CMD_MARKER)) {
System.out.println(line);
line = line.substring(CMD_MARKER.length());
command = parse(line);
} else if (line.startsWith(RES_MARKER)) {
System.out.println(line);
line = line.substring(RES_MARKER.length());
Bytes response = parseWildcard(line);
CommandAPDU capdu = new CommandAPDU(command);
ResponseAPDU rapdu = channel.transmit(capdu);
byte[] received = rapdu.getBytes();
if (received.length != response.bytes.length) {
throw new Exception("Length mismatch: " + toString(received));
}
for (int i = 0; i < received.length; i++) {
byte mask = response.mask[i];
if ((received[i] & response.mask[i]) != response.bytes[i]) {
throw new Exception("Mismatch: " + toString(received));
}
}
} // else ignore
}
// disconnect
card.disconnect(true);
System.out.println("OK.");
}
示例14: BeIDCard
import javax.smartcardio.Card; //导入方法依赖的package包/类
/**
* Instantiate a BeIDCard from an already connected javax.smartcardio.Card,
* with a Logger implementation to receive logging output.
*
* @param card
* a javax.smartcardio.Card that you have previously determined
* to be a BeID Card
* @param logger
* an instance of be.fedict.commons.eid.spi.Logger
* @throws IllegalArgumentException
* when passed a null logger. to disable logging, call
* BeIDCard(Card) instead.
* @throws RuntimeException
* when no CertificateFactory capable of producing X509
* Certificates is available.
*/
public BeIDCard(final Card card, final Logger logger) {
this.card = card;
this.cardChannel = card.getBasicChannel();
if (null == logger) {
throw new IllegalArgumentException("logger expected");
}
this.logger = logger;
this.cardListeners = new LinkedList<BeIDCardListener>();
try {
this.certificateFactory = CertificateFactory.getInstance("X.509");
} catch (final CertificateException e) {
throw new RuntimeException("X.509 algo", e);
}
}