本文整理汇总了Java中javax.smartcardio.CardChannel类的典型用法代码示例。如果您正苦于以下问题:Java CardChannel类的具体用法?Java CardChannel怎么用?Java CardChannel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CardChannel类属于javax.smartcardio包,在下文中一共展示了CardChannel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testReadPhoto
import javax.smartcardio.CardChannel; //导入依赖的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.CardChannel; //导入依赖的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.CardChannel; //导入依赖的package包/类
private static CardChannel Connect(MPCRunConfig runCfg) throws Exception {
switch (runCfg.testCardType) {
case PHYSICAL: {
return ConnectPhysicalCard(runCfg.targetReaderIndex, runCfg.appletAID);
}
case JCOPSIM: {
return ConnectJCOPSimulator(runCfg.targetReaderIndex, runCfg.appletAID);
}
case JCARDSIMLOCAL: {
return ConnectJCardSimLocalSimulator(runCfg.appletToSimulate, runCfg.appletAID);
}
case JCARDSIMREMOTE: {
return null; // Not implemented yet
}
default:
return null;
}
}
示例4: transmit
import javax.smartcardio.CardChannel; //导入依赖的package包/类
private ResponseAPDU transmit(CardChannel channel, CommandAPDU cmd)
throws CardException {
log(cmd);
long elapsed = -System.currentTimeMillis();
ResponseAPDU response = channel.transmit(cmd);
elapsed += System.currentTimeMillis();
lastTransmitTime = elapsed;
log(response, elapsed);
return response;
}
示例5: Connect
import javax.smartcardio.CardChannel; //导入依赖的package包/类
private static CardChannel Connect(MPCRunConfig runCfg) throws Exception {
switch (runCfg.testCardType) {
case PHYSICAL: {
return CardManagement.ConnectPhysicalCard(runCfg.targetReaderIndex, runCfg.appletAID);
}
case JCOPSIM: {
return CardManagement.ConnectJCOPSimulator(runCfg.targetReaderIndex, runCfg.appletAID);
}
case JCARDSIMLOCAL: {
return CardManagement.ConnectJCardSimLocalSimulator(runCfg.appletToSimulate, runCfg.appletAID);
}
case JCARDSIMREMOTE: {
return null; // Not implemented yet
}
default:
return null;
}
}
示例6: testCardManager
import javax.smartcardio.CardChannel; //导入依赖的package包/类
@Test
public void testCardManager() throws Exception {
final PcscEid pcscEid = new PcscEid(new TestView(), this.messages);
if (false == pcscEid.isEidPresent()) {
LOG.debug("insert eID card");
pcscEid.waitForEidPresent();
}
View view = new TestView();
CardChannel cardChannel = pcscEid.getCardChannel();
selectCardManager(cardChannel);
// card manager active
TaskRunner taskRunner = new TaskRunner(pcscEid, view);
try {
byte[] data = taskRunner.run(new Task<byte[]>() {
public byte[] run() throws Exception {
return pcscEid.readFile(PcscEid.IDENTITY_FILE_ID);
}
});
assertNotNull(data);
} finally {
pcscEid.close();
}
}
示例7: testCardDataFile
import javax.smartcardio.CardChannel; //导入依赖的package包/类
@Test
public void testCardDataFile() throws Exception {
PcscEid pcscEid = new PcscEid(new TestView(), this.messages);
if (false == pcscEid.isEidPresent()) {
LOG.debug("insert eID card");
pcscEid.waitForEidPresent();
}
try {
CardChannel cardChannel = pcscEid.getCardChannel();
while (true) {
CommandAPDU getCardApdu = new CommandAPDU(0x80, 0xe4, 0x00, 0x00, 0x1c); // Le
// =
// 0x1c
ResponseAPDU responseApdu = cardChannel.transmit(getCardApdu);
if (0x9000 != responseApdu.getSW()) {
fail("SW error: " + Integer.toHexString(responseApdu.getSW()));
}
LOG.debug(Hex.encodeHexString(responseApdu.getData()));
}
} finally {
pcscEid.close();
}
}
示例8: testGetChallenge
import javax.smartcardio.CardChannel; //导入依赖的package包/类
@Test
public void testGetChallenge() throws Exception {
PcscEid pcscEid = new PcscEid(new TestView(), this.messages);
if (false == pcscEid.isEidPresent()) {
LOG.debug("insert eID card");
pcscEid.waitForEidPresent();
}
CardChannel cardChannel = pcscEid.getCardChannel();
int size = 256;
CommandAPDU getChallengeApdu = new CommandAPDU(0x00, 0x84, 0x00, 0x00, new byte[] {}, 0, 0, size);
ResponseAPDU responseApdu;
responseApdu = cardChannel.transmit(getChallengeApdu);
if (0x9000 != responseApdu.getSW()) {
fail("get challenge failure: " + Integer.toHexString(responseApdu.getSW()));
}
LOG.debug("challenge: " + Hex.encodeHexString(responseApdu.getData()));
assertEquals(size, responseApdu.getData().length);
pcscEid.close();
}
示例9: getBasicChannel
import javax.smartcardio.CardChannel; //导入依赖的package包/类
public CardChannel getBasicChannel()
throws IllegalStateException
{
if(verbosity > 0) {
System.out.println("JC card basic channel");
}
// XXX check security and disconnect!
check_not_disconnected();
if(basic_channel == null) {
basic_channel =
new Emulator_connection_channel(jcard, this, 0, verbosity);
}
return basic_channel;
}
示例10: performCommand
import javax.smartcardio.CardChannel; //导入依赖的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;
}
示例11: openLogicalChannel
import javax.smartcardio.CardChannel; //导入依赖的package包/类
/**
* Open a logical channel.
*
* <p>
* Common exceptions:
* <ul>
* <li>JnaCardException(6200): processing warning
* <li>JnaCardException(6881): logical channel not supported
* <li>JnaCardException(6a81): function not supported
* </ul>
*/
@Override public CardChannel openLogicalChannel() throws CardException {
// manage channel: request a new logical channel from 0x01 to 0x13
JnaCardChannel basicChannel = getBasicChannel();
ResponseAPDU response = basicChannel.transmit(new CommandAPDU(0, 0x70, 0x00, 0x00, 1));
int sw = response.getSW();
if (0x9000 == sw) {
byte[] body = response.getData();
if (body.length == 1) {
int channel = 0xff & body[0];
if (channel == 0 || channel > 0x13)
throw new JnaCardException(sw, String.format("Expected manage channel response to contain channel number in 1-19; got %d", channel));
return new JnaCardChannel(this, channel);
} else {
throw new JnaCardException(sw, String.format("Expected body of length 1 in response to manage channel request; got %d", body.length));
}
} else {
throw new JnaCardException(sw, String.format("Error: sw=%04x in response to manage channel command.", sw));
}
}
示例12: ConnectJCardSimLocalSimulator
import javax.smartcardio.CardChannel; //导入依赖的package包/类
private CardChannel ConnectJCardSimLocalSimulator(Class appletClass) throws Exception {
System.setProperty("com.licel.jcardsim.terminal.type", "2");
CAD cad = new CAD(System.getProperties());
JavaxSmartCardInterface simulator = (JavaxSmartCardInterface) cad.getCardInterface();
byte[] installData = new byte[0];
AID appletAID = new AID(m_APPLET_AID, (short) 0, (byte) m_APPLET_AID.length);
AID appletAIDRes = simulator.installApplet(appletAID, appletClass, installData, (short) 0, (byte) installData.length);
simulator.selectApplet(appletAID);
return new SimulatedCardChannelLocal(simulator);
}
示例13: transmitTestCommand
import javax.smartcardio.CardChannel; //导入依赖的package包/类
static void transmitTestCommand(CardChannel channel) throws Exception {
ResponseAPDU r = channel.transmit(new CommandAPDU(C1));
byte[] rb = r.getBytes();
if ((Arrays.equals(rb, R1a) == false) && (Arrays.equals(rb, R1b) == false)) {
System.out.println("expected: " + toString(R1a));
System.out.println("received: " + toString(rb));
throw new Exception("Response does not match");
}
}
示例14: connectToAllCardsByTerminalFactory
import javax.smartcardio.CardChannel; //导入依赖的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());
}
示例15: ConnectJCardSimLocalSimulator
import javax.smartcardio.CardChannel; //导入依赖的package包/类
public static CardChannel ConnectJCardSimLocalSimulator(Class appletClass, byte[] appAID) throws Exception {
System.setProperty("com.licel.jcardsim.terminal.type", "2");
CAD cad = new CAD(System.getProperties());
JavaxSmartCardInterface simulator = (JavaxSmartCardInterface) cad.getCardInterface();
byte[] installData = new byte[0];
AID appletAID = new AID(appAID, (short) 0, (byte) appAID.length);
AID appletAIDRes = simulator.installApplet(appletAID, appletClass, installData, (short) 0, (byte) installData.length);
simulator.selectApplet(appletAID);
return new SimulatedCardChannelLocal(simulator, appletAIDRes);
}