Example usage for javax.smartcardio ResponseAPDU getBytes

List of usage examples for javax.smartcardio ResponseAPDU getBytes

Introduction

In this page you can find the example usage for javax.smartcardio ResponseAPDU getBytes.

Prototype

public byte[] getBytes() 

Source Link

Document

Returns a copy of the bytes in this APDU.

Usage

From source file:NFC.IsmbSnepConnectionTarget.java

/**
 * Sends and receives APDUs to and from the controller
 *
 * @param instr//from  w ww . j  ava2  s. c om
 *            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 . ja  v  a  2  s.  c  o 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;
}

From source file:org.opensc.pkcs15.script.SimpleCommand.java

@Override
public Command execute(CardChannel channel) throws CardException {

    log.debug("Tranmitting APDU [" + Util.asHex(this.getRequest().getBytes()) + "].");

    ResponseAPDU resp = channel.transmit(this.getRequest());

    log.debug("Got response [" + Util.asHex(resp.getBytes()) + "].");

    return this.checkResponse(resp);
}