Example usage for javax.smartcardio Card getBasicChannel

List of usage examples for javax.smartcardio Card getBasicChannel

Introduction

In this page you can find the example usage for javax.smartcardio Card getBasicChannel.

Prototype

public abstract CardChannel getBasicChannel();

Source Link

Document

Returns the CardChannel for the basic logical channel.

Usage

From source file:eu.abc4trust.smartcard.HardwareSmartcard.java

/**
 * /*  w  ww.ja v a2  s  . com*/
 * @param terminal
 * @param card
 * @param file A file describing the credential URI to ID mapping. If null, it is assumed that no mapping is done yet.
 */
public HardwareSmartcard(CardTerminal terminal, Card card, Random rand) {
    this.terminal = terminal;
    this.channel = card.getBasicChannel();
    this.card = card;
    this.rand = rand;
}

From source file:src.eidreader.EstEIDUtil.java

public String readCard(final Boolean full) {
    System.err.println("EIDReader.readCard()");
    return AccessController.doPrivileged(new PrivilegedAction<String>() {
        public String run() {
            try {
                TerminalFactory factory = TerminalFactory.getDefault();
                List<CardTerminal> terminals = factory.terminals().list();

                if (terminals.size() == 0) {
                    return "Error: No card reader found";
                }/*www .  j  a v a 2s  . c  o m*/
                //~ throws java.lang.IndexOutOfBoundsException when there is no reader
                CardTerminal terminal = terminals.get(0);

                if (!terminal.isCardPresent()) {
                    return "Error: No card found on terminal";
                    //~ return new EidReaderResponse(new String[] { "No card found on terminal" });
                }
                // "The best way to go is, as explained by Shane, to use the wildcard protocol."
                // https://forums.oracle.com/message/10531935
                Card card = terminal.connect("T=0");
                // Card card = terminal.connect("T=1");
                // Card card = terminal.connect("*");
                System.err.println("Protocol: " + card.getProtocol());
                ATR atr = card.getATR();

                CardChannel channel = card.getBasicChannel();

                if (BelgianReader.matchesEidAtr(atr)) {
                    System.err.println("It's a Belgian card");
                    BelgianReader pf = new BelgianReader(channel);
                    return pf.resultAsString(full);
                }

                System.err.println("It's an Estonian card");
                PersonalFile pf = new PersonalFile(channel);
                return pf.resultAsString(full);
                //~ return new String[] { pf.toString() };
                //~ return new EidReaderResponse(pf.getData());
                //~ return pf.getSurName();
            } catch (Throwable e) {
                //~ return new EidReaderResponse(new String[] { e.toString() });
                e.printStackTrace();
                return "Error: " + e.toString();
            }
        }
    });
}

From source file:test.be.fedict.eid.applet.PcscTest.java

@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(//w w  w. j  a  v a  2 s  .c  o  m
            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));
}