当前位置: 首页>>代码示例>>Java>>正文


Java CardTerminal类代码示例

本文整理汇总了Java中javax.smartcardio.CardTerminal的典型用法代码示例。如果您正苦于以下问题:Java CardTerminal类的具体用法?Java CardTerminal怎么用?Java CardTerminal使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CardTerminal类属于javax.smartcardio包,在下文中一共展示了CardTerminal类的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));
}
 
开发者ID:e-Contract,项目名称:eid-applet,代码行数:23,代码来源:PcscTest.java

示例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");
		}

	}
 
开发者ID:devnied,项目名称:EMV-NFC-Paycard-Enrollment,代码行数:27,代码来源:Main.java

示例3: insertTerminal

import javax.smartcardio.CardTerminal; //导入依赖的package包/类
private void insertTerminal(Class<? extends Applet> card) throws CardException
{
	if (card != null)
	{
		CardSimulator simulator = new CardSimulator();
		AID appletAID = AIDUtil.create("D2760000015445535442");
		simulator.installApplet(appletAID, card);
		CardTerminal terminal = CardTerminalSimulator.terminal(simulator);
		CommandAPDU selectCommand = new CommandAPDU(AIDUtil.select(appletAID));
		simulator.transmitCommand(selectCommand);
		terminallist.add(terminal);
		terminallistCardPresent.add(terminal);
	}
	else
	{
		CardTerminal emptyTerminal = EasyMock.createNiceMock(CardTerminal.class);
		EasyMock.expect(emptyTerminal.connect(EasyMock.anyString())).andThrow(
				new javax.smartcardio.CardNotPresentException("no card found"));
		EasyMock.expect(emptyTerminal.isCardPresent()).andReturn(false);
		EasyMock.replay(emptyTerminal);
		terminallist.add(emptyTerminal);
	}
}
 
开发者ID:patrick-werner,项目名称:EGKfeuer,代码行数:24,代码来源:CardReaderServiceTest.java

示例4: 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;
}
 
开发者ID:EsupPortail,项目名称:esup-nfc-tag-server,代码行数:27,代码来源:SimpleSCR.java

示例5: 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;
}
 
开发者ID:tsenger,项目名称:animamea,代码行数:31,代码来源:AmCardHandler.java

示例6: getSignatureCards

import javax.smartcardio.CardTerminal; //导入依赖的package包/类
private List<SignatureCard> getSignatureCards() {

		if (_signatureCards == null) {

			_signatureCards = new ArrayList<SignatureCard>();
			SmartCardIO io = new SmartCardIO();
			SignatureCardFactory factory = SignatureCardFactory.getInstance();

			for (Entry<CardTerminal, Card> entry : io.getCards().entrySet()) {
				try {
					_signatureCards.add(factory.createSignatureCard(entry.getValue(), entry.getKey()));
				} catch (CardNotSupportedException e) {
					// just log the error - MOCCA tries to connect to all cards and we may have an MSCAPI or PKCS11 also
					// inserted.
					LOG.info(e.getMessage());
				}
			}
		}
		return _signatureCards;
	}
 
开发者ID:esig,项目名称:dss,代码行数:21,代码来源:MOCCASignatureTokenConnection.java

示例7: 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;
}
 
开发者ID:mobilesec,项目名称:secure-element-gpdroid-nfc,代码行数:33,代码来源:GPConnection.java

示例8: refreshCards

import javax.smartcardio.CardTerminal; //导入依赖的package包/类
/**
 * Refreshes the cached {@link BeIDCard}s, and replaces any instances that
 * are in an unusable state (SCARD_W_RESET_CARD).
 */
public void refreshCards() {
	synchronized (this.terminalsAndCards) {
		for (Entry<CardTerminal, BeIDCard> terminalsAndCard : this.terminalsAndCards.entrySet()) {
			BeIDCard beIDCard = terminalsAndCard.getValue();
			try {
				beIDCard.beginExclusive();
				beIDCard.endExclusive();
			} catch (CardException e) {
				this.logger.error("begin exclusive failed: " + e.getMessage() + " - replacing BeIDCard instance");
				beIDCard.close();
				CardTerminal cardTerminal = terminalsAndCard.getKey();
				try {
					BeIDCard newBeIDCard = createBeIDCard(cardTerminal, cardTerminal.connect("T=0"));
					terminalsAndCard.setValue(newBeIDCard);
					notifyEIDCardInserted(cardTerminal, newBeIDCard);
				} catch (CardException e1) {
					this.logger.error("card refresh failed: " + e1.getMessage());
				}
			}
		}
	}
}
 
开发者ID:e-Contract,项目名称:commons-eid,代码行数:27,代码来源:BeIDCardManager.java

示例9: terminalsWithCardsIn

import javax.smartcardio.CardTerminal; //导入依赖的package包/类
private Set<CardTerminal> terminalsWithCardsIn(
		final Set<CardTerminal> terminals) {
	final Set<CardTerminal> terminalsWithCards = new HashSet<CardTerminal>();

	synchronized (this.terminalsToIgnoreCardEventsFor) {
		for (CardTerminal terminal : terminals) {
			try {
				if (terminal.isCardPresent()
						&& !this.areCardEventsIgnoredFor(terminal)) {
					terminalsWithCards.add(terminal);
				}
			} catch (final CardException cex) {
				this.logger
						.error("Problem determining card presence in terminal ["
								+ terminal.getName() + "]", cex);
			}
		}
	}

	return terminalsWithCards;
}
 
开发者ID:e-Contract,项目名称:commons-eid,代码行数:22,代码来源:CardAndTerminalManager.java

示例10: listenersTerminalsAttached

import javax.smartcardio.CardTerminal; //导入依赖的package包/类
private void listenersTerminalsAttached(final Set<CardTerminal> attached) {
	if (!attached.isEmpty()) {
		Set<CardTerminalEventsListener> copyOfListeners;

		synchronized (this.cardTerminalEventsListeners) {
			copyOfListeners = new HashSet<CardTerminalEventsListener>(
					this.cardTerminalEventsListeners);
		}

		for (CardTerminal terminal : attached) {
			for (CardTerminalEventsListener listener : copyOfListeners) {
				try {
					listener.terminalAttached(terminal);
				} catch (final Exception thrownInListener) {
					this.logger
							.error("Exception thrown in CardTerminalEventsListener.terminalAttached:"
									+ thrownInListener.getMessage());
				}
			}
		}
	}
}
 
开发者ID:e-Contract,项目名称:commons-eid,代码行数:23,代码来源:CardAndTerminalManager.java

示例11: listenersTerminalsDetached

import javax.smartcardio.CardTerminal; //导入依赖的package包/类
private void listenersTerminalsDetached(final Set<CardTerminal> detached) {
	if (!detached.isEmpty()) {
		Set<CardTerminalEventsListener> copyOfListeners;

		synchronized (this.cardTerminalEventsListeners) {
			copyOfListeners = new HashSet<CardTerminalEventsListener>(
					this.cardTerminalEventsListeners);
		}

		for (CardTerminal terminal : detached) {
			for (CardTerminalEventsListener listener : copyOfListeners) {
				try {
					listener.terminalDetached(terminal);
				} catch (final Exception thrownInListener) {
					this.logger
							.error("Exception thrown in CardTerminalEventsListener.terminalDetached:"
									+ thrownInListener.getMessage());
				}
			}
		}
	}
}
 
开发者ID:e-Contract,项目名称:commons-eid,代码行数:23,代码来源:CardAndTerminalManager.java

示例12: listenersTerminalsWithCardsRemoved

import javax.smartcardio.CardTerminal; //导入依赖的package包/类
private void listenersTerminalsWithCardsRemoved(
		final Set<CardTerminal> removed) {
	if (!removed.isEmpty()) {
		Set<CardEventsListener> copyOfListeners;

		synchronized (this.cardEventsListeners) {
			copyOfListeners = new HashSet<CardEventsListener>(
					this.cardEventsListeners);
		}

		for (CardTerminal terminal : removed) {
			for (CardEventsListener listener : copyOfListeners) {
				try {
					listener.cardRemoved(terminal);
				} catch (final Exception thrownInListener) {
					this.logger
							.error("Exception thrown in CardEventsListener.cardRemoved:"
									+ thrownInListener.getMessage());
				}
			}
		}
	}
}
 
开发者ID:e-Contract,项目名称:commons-eid,代码行数:24,代码来源:CardAndTerminalManager.java

示例13: getTerminal

import javax.smartcardio.CardTerminal; //导入依赖的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;
}
 
开发者ID:infobip,项目名称:infobip-open-jdk-8,代码行数:22,代码来源:Utils.java

示例14: 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.");
}
 
开发者ID:frohoff,项目名称:jdk8u-dev-jdk,代码行数:14,代码来源:TestDirect.java

示例15: run

import javax.smartcardio.CardTerminal; //导入依赖的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());
	}

}
 
开发者ID:intarsys,项目名称:smartcard-io,代码行数:17,代码来源:ListReaders.java


注:本文中的javax.smartcardio.CardTerminal类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。