List of usage examples for javax.smartcardio CardException CardException
public CardException(Throwable cause)
From source file:Main.java
/** * Establishes the connection with the Smart Card (if present) * using the first available terminal.//w w w. j av a 2s .co m */ public static Card connectCard() throws CardException { // Get available terminals List<CardTerminal> terminals = TerminalFactory.getDefault().terminals().list(); if (terminals.size() < 1) { throw new CardException("No attached Smart Card terminals found"); } // Search for connected cards Card card = null; for (CardTerminal terminal : terminals) { if (terminal.isCardPresent()) { card = terminal.connect("*"); break; } } if (card == null) { throw new CardException("No connected Smart Cards found"); } return card; }
From source file:NFC.IsmbSnepConnectionTarget.java
/** * Sends and receives APDUs to and from the controller * * @param instr//from www. j a va 2 s. co m * Instruction * @param param * Payload to send * * @return The response payload */ private byte[] transceive(byte instr, byte[] payload) throws IsmbSnepException { if (ch == null) { throw new IsmbSnepException("channel not open"); } int payloadLength = (payload != null) ? payload.length : 0; byte[] instruction = { (byte) 0xd4, instr }; //ACR122 header byte[] header = { (byte) 0xff, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) (instruction.length + payloadLength) }; /* construct the command */ byte[] cmd = Util.appendToByteArray(header, instruction, 0, instruction.length); cmd = Util.appendToByteArray(cmd, payload); if (debugMode) Util.debugAPDUs(cmd, null); try { CommandAPDU c = new CommandAPDU(cmd); ResponseAPDU r = ch.transmit(c); byte[] ra = r.getBytes(); if (debugMode) Util.debugAPDUs(null, ra); /* check whether APDU command was accepted by the Controller */ if (r.getSW1() == 0x63 && r.getSW2() == 0x27) { throw new CardException("wrong checksum from contactless response"); } else if (r.getSW1() == 0x63 && r.getSW2() == 0x7f) { throw new CardException("wrong PN53x command"); } else if (r.getSW1() != 0x90 && r.getSW2() != 0x00) { throw new CardException("unknown error"); } return Util.subByteArray(ra, 2, ra.length - 4); } catch (CardException e) { throw new IsmbSnepException("problem with transmitting data"); } }
From source file:org.opensc.pkcs15.script.SimpleCommand.java
protected Command checkResponse(ResponseAPDU resp) throws CardException { if (!doCheckResponse(resp.getBytes(), this.response)) { String msg;/* ww w . jav a 2 s .co m*/ if (this.getResponse() != null) { msg = "Response [" + Util.asHex(resp.getBytes()) + "] from card differs from expected response [" + Util.asHexMask(this.getResponse()) + "]."; } else { msg = "Response [" + Util.asHex(resp.getBytes()) + "] from card does not signify success."; } if (this.isCheckResponse()) throw new CardException(msg); else log.warn(msg); } return this.next; }