Example usage for javax.smartcardio CommandAPDU CommandAPDU

List of usage examples for javax.smartcardio CommandAPDU CommandAPDU

Introduction

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

Prototype

public CommandAPDU(int cla, int ins, int p1, int p2, byte[] data, int dataOffset, int dataLength, int ne) 

Source Link

Document

Constructs a CommandAPDU from the four header bytes, command data, and expected response data length.

Usage

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

@Test
public void testGetChallenge() throws Exception {
    PcscEid pcscEid = new PcscEid(new TestView(), this.messages);
    if (false == pcscEid.isEidPresent()) {
        LOG.debug("insert eID card");
        pcscEid.waitForEidPresent();//w w  w  .j a  va 2 s.  c  om
    }

    CardChannel cardChannel = pcscEid.getCardChannel();

    int size = 256;
    CommandAPDU getChallengeApdu = new CommandAPDU(0x00, 0x84, 0x00, 0x00, new byte[] {}, 0, 0, size);
    ResponseAPDU responseApdu;
    responseApdu = cardChannel.transmit(getChallengeApdu);
    if (0x9000 != responseApdu.getSW()) {
        fail("get challenge failure: " + Integer.toHexString(responseApdu.getSW()));
    }
    LOG.debug("challenge: " + Hex.encodeHexString(responseApdu.getData()));
    assertEquals(size, responseApdu.getData().length);

    pcscEid.close();
}