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


Java Card类代码示例

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


Card类属于javax.smartcardio包,在下文中一共展示了Card类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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));
}
 
开发者ID:e-Contract,项目名称:eid-applet,代码行数:23,代码来源:PcscTest.java

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

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

示例3: getSignatureCards

import javax.smartcardio.Card; //导入依赖的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

示例4: performCommand

import javax.smartcardio.Card; //导入依赖的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

示例5: getFeaturesUsingPPDU

import javax.smartcardio.Card; //导入依赖的package包/类
private void getFeaturesUsingPPDU(final Card card) throws CardException {
	ResponseAPDU responseAPDU = card.getBasicChannel().transmit(
			new CommandAPDU((byte) 0xff, (byte) 0xc2, 0x01, 0x00,
					new byte[]{}, 32));
	this.logger.debug("PPDU response: "
			+ Integer.toHexString(responseAPDU.getSW()));
	if (responseAPDU.getSW() == 0x9000) {
		byte[] featureBytes = responseAPDU.getData();
		this.logger
				.debug("CCID FEATURES found using Pseudo-APDU Fallback Strategy");
		for (FEATURE feature : FEATURE.values()) {
			Integer featureCode = findFeaturePPDU(feature.getTag(),
					featureBytes);
			if (featureCode != null) {
				this.features.put(feature, featureCode);
				this.logger.debug("FEATURE " + feature.name() + " = "
						+ Integer.toHexString(featureCode));
			}
		}
		this.usesPPDU = true;
	} else {
		this.logger.error("CCID Features via PPDU Not Supported");
	}
}
 
开发者ID:e-Contract,项目名称:commons-eid,代码行数:25,代码来源:CCID.java

示例6: main

import javax.smartcardio.Card; //导入依赖的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

示例7: connect

import javax.smartcardio.Card; //导入依赖的package包/类
@Override
public Card connect(String protocol) throws CardException {
	try {
		HashMap<String, Object> m = new HashMap<>();
		m.put("cmd", "CONNECT");
		m.put("protocol", protocol);
		client.send(m);

		// Read back the response
		Map<String, Object> r = client.recv();
		if (r.containsKey("CONNECT") && ((String)r.get("CONNECT")).equals("OK")) {

			if (r.containsKey("atr") && r.containsKey("protocol") && r.containsKey("reader")) {
				terminalName = (String) r.get("reader");
				atr = new ATR(HexUtils.stringToBin((String) r.get("atr")));
				this.protocol = ((String) r.get("protocol"));
				return new JSONCard(this);
			}
		}
		throw new CardException("Could not connect to client");
	} catch (IOException e) {
		throw new CardException("Could not connect to client", e);
	}

}
 
开发者ID:martinpaljak,项目名称:apdu4j,代码行数:26,代码来源:JSONCardTerminal.java

示例8: sendAcrGetData

import javax.smartcardio.Card; //导入依赖的package包/类
/**
 * Send Access Control rule GET DATA.
 *
 * @param card
 * @param P1
 * @return
 * @throws CardException
 * @throws GPException
 */
private static ResponseAPDU sendAcrGetData(final Card card, final byte P1) throws CardException, GPException {
	CommandAPDU list = new CommandAPDU(GlobalPlatform.CLA_GP, GlobalPlatform.INS_GET_DATA, 0xFF, P1, 256);

	ResponseAPDU response = card.getBasicChannel().transmit(list);

	try {
		GPException.check(response, "ACR GET DATA failed");
	} catch (GPException e) {
		if (SEAccessControl.ACR_GET_DATA_ERROR.containsKey(e.sw)) {
			System.out.println("[SW] " + SEAccessControl.ACR_GET_DATA_ERROR.get(e.sw));
		}
		throw e;
	}
	return response;
}
 
开发者ID:martinpaljak,项目名称:GlobalPlatformPro,代码行数:25,代码来源:SEAccessControlUtility.java

示例9: acrList

import javax.smartcardio.Card; //导入依赖的package包/类
/**
 * List access rules.
 *
 * @param card
 * @throws CardException
 * @throws GPException
 */
public static void acrList(final GlobalPlatform gp, final Card card) throws CardException, GPException {
	try {
		gp.select(SEAccessControl.ACR_AID);
		ResponseAPDU response = sendAcrGetData(card, SEAccessControl.ACR_GET_DATA_ALL);
		SEAccessControl.BerTlvData temp = SEAccessControl.AcrListResponse.getAcrListData(null, response.getData());

		while (temp.getCurrentIndex() < temp.getLength()) {
			response = sendAcrGetData(card, SEAccessControl.ACR_GET_DATA_NEXT);
			temp = SEAccessControl.AcrListResponse.getAcrListData(temp, response.getData());
		}

		SEAccessControl.AcrListResponse resp = SEAccessControl.AcrListResponse.fromBytes(temp.getLength(), temp.getData());
		SEAccessControl.printList(resp.acrList);
	} catch (GPException e) {
		throw new GPException("Could not read " + SEAccessControl.ACR_AID);
	}
}
 
开发者ID:martinpaljak,项目名称:GlobalPlatformPro,代码行数:25,代码来源:SEAccessControlUtility.java

示例10: updateTerminal

import javax.smartcardio.Card; //导入依赖的package包/类
void updateTerminal() {
if (! isCardPresent()) {
    scCard = null;
} else {
    try {
	if (scCard != null) {
	    // check if it is the same card, else remove
	    Card newCard = terminal.connect("*");
	    if (! scCard.equalCardObj(newCard)) {
		scCard = null;
	    }
	}
    } catch (CardException ex) {
	// error means delete it anyways
	scCard = null;
    }
}
   }
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:19,代码来源:SCTerminal.java

示例11: connect

import javax.smartcardio.Card; //导入依赖的package包/类
@Override
   public synchronized Card connect(String arg0) throws CardException {
if (nfcCard == null || this.nfcCard.isodep == null) {
    logger.warn("No tag present.");
    throw new CardNotPresentException("No tag present");
}
try {
    if (! nfcCard.isodep.isConnected()) {
	nfcCard.isodep.setTimeout(3000);
	nfcCard.isodep.connect();
    }
} catch (IOException e) {
    nfcCard = null;
    throw new CardException("No connection could be established", e);
}
return nfcCard;
   }
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:18,代码来源:NFCCardTerminal.java

示例12: SmartcardIoTransmitter

import javax.smartcardio.Card; //导入依赖的package包/类
public SmartcardIoTransmitter(Card card) {
    this.card = card;
}
 
开发者ID:identiv,项目名称:ts-cards,代码行数:4,代码来源:SmartcardIoTransmitter.java

示例13: create

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

}
 
开发者ID:identiv,项目名称:ts-cards,代码行数:30,代码来源:SmartcardIoTransmitter.java

示例14: waitForCard

import javax.smartcardio.Card; //导入依赖的package包/类
private Card waitForCard(CardTerminals terminals)
        throws CardException {
    while (true) {
        for (CardTerminal ct : terminals
                .list(CardTerminals.State.CARD_INSERTION)) {

            return ct.connect("*");
        }
        terminals.waitForChange();
    }
}
 
开发者ID:OpenCryptoProject,项目名称:JCMathLib,代码行数:12,代码来源:CardManager.java

示例15: main

import javax.smartcardio.Card; //导入依赖的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.");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:16,代码来源:TestDirect.java


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