Note that when the expected length of the response APDU is specified in the constructors, the actual length (Ne) must be specified, not its encoded form (Le). Similarly, getNe returns the actual value Ne. In other words, a value of 0 means "no data in the response APDU" rather than "maximum length."
This class supports both the short and extended forms of length encoding for Ne and Nc. However, note that not all terminals and Smart Cards are capable of accepting APDUs that use the extended form.
For the header bytes CLA, INS, P1, and P2 the Java type int
is used to represent the 8 bit unsigned values. In the constructors, only
the 8 lowest bits of the int value specified by the application
are significant. The accessor methods always return the byte as an unsigned
value between 0 and 255.
Instances of this class are immutable. Where data is passed in or out via byte arrays, defensive cloning is performed.
ResponseAPDU, CardChannel.transmit
| Modifier and Type | Field and Description |
|---|---|
| private byte[] | |
| private transient int | |
| private static final int | |
| private transient int | |
| private transient int | |
| private static final long |
| Access | Constructor and Description |
|---|---|
| public | CommandAPDU(byte[]
the complete command APDU apdu)Constructs a CommandAPDU from a byte array containing the complete APDU contents (header and body). |
| public | CommandAPDU(byte[]
the complete command APDU apdu, int the offset in the byte array at which the apdu
data begins apduOffset, int the length of the APDU apduLength)Constructs a CommandAPDU from a byte array containing the complete APDU contents (header and body). |
| public | CommandAPDU(ByteBuffer
the ByteBuffer containing the complete APDU apdu)Creates a CommandAPDU from the ByteBuffer containing the complete APDU contents (header and body). |
| public | CommandAPDU(int
the class byte CLA cla, int the instruction byte INS ins, int the parameter byte P1 p1, int the parameter byte P2 p2)Constructs a CommandAPDU from the four header bytes. |
| public | CommandAPDU(int
the class byte CLA cla, int the instruction byte INS ins, int the parameter byte P1 p1, int the parameter byte P2 p2, int the maximum number of expected data bytes in a response APDU ne)Constructs a CommandAPDU from the four header bytes and the expected response data length. |
| public | CommandAPDU(int
the class byte CLA cla, int the instruction byte INS ins, int the parameter byte P1 p1, int the parameter byte P2 p2, byte[] the byte array containing the data bytes of the command body data)Constructs a CommandAPDU from the four header bytes and command data. |
| public | CommandAPDU(int
the class byte CLA cla, int the instruction byte INS ins, int the parameter byte P1 p1, int the parameter byte P2 p2, byte[] the byte array containing the data bytes of the command body data, int the offset in the byte array at which the data
bytes of the command body begin dataOffset, int the number of the data bytes in the command body dataLength)Constructs a CommandAPDU from the four header bytes and command data. |
| public | CommandAPDU(int
the class byte CLA cla, int the instruction byte INS ins, int the parameter byte P1 p1, int the parameter byte P2 p2, byte[] the byte array containing the data bytes of the command body data, int the maximum number of expected data bytes in a response APDU ne)Constructs a CommandAPDU from the four header bytes, command data, and expected response data length. |
| public | CommandAPDU(int
the class byte CLA cla, int the instruction byte INS ins, int the parameter byte P1 p1, int the parameter byte P2 p2, byte[] the byte array containing the data bytes of the command body data, int the offset in the byte array at which the data
bytes of the command body begin dataOffset, int the number of the data bytes in the command body dataLength, int the maximum number of expected data bytes in a response APDU ne)Constructs a CommandAPDU from the four header bytes, command data, and expected response data length. |
| Modifier and Type | Method and Description |
|---|---|
| private static int | |
| private void | |
| public boolean | Returns: true if the specified object is equal to this command APDUthe object to be compared for equality with this command APDU obj)Overrides java. Compares the specified object with this command APDU for equality. |
| public byte[] | |
| public int | |
| public byte[] | Returns: a copy of the data bytes in the command body or the empty byte array if this APDU has no body.Returns a copy of the data bytes in the command body. |
| public int | Returns: the value of the instruction byte INS.Returns the value of the instruction byte INS. |
| public int | Returns: the number of data bytes in the command body or 0 if this APDU has no body.Returns the number of data bytes in the command body (Nc) or 0 if this APDU has no body. |
| public int | Returns: the maximum number of expected data bytes in a response APDU.Returns the maximum number of expected data bytes in a response APDU (Ne). |
| public int | |
| public int | |
| public int | Returns: the hash code value for this command APDU.Overrides java. Returns the hash code value for this command APDU. |
| private void | parse()
Command APDU encoding options: case 1: |CLA|INS|P1 |P2 | len = 4 case 2s: |CLA|INS|P1 |P2 |LE | len = 5 case 3s: |CLA|INS|P1 |P2 |LC |...BODY...| len = 6..260 case 4s: |CLA|INS|P1 |P2 |LC |...BODY...|LE | len = 7..261 case 2e: |CLA|INS|P1 |P2 |00 |LE1|LE2| len = 7 case 3e: |CLA|INS|P1 |P2 |00 |LC1|LC2|...BODY...| len = 8..65542 case 4e: |CLA|INS|P1 |P2 |00 |LC1|LC2|...BODY...|LE1|LE2| len =10..65544 LE, LE1, LE2 may be 0x00. |
| private void | |
| private void | |
| public String | Returns: a String representation of this command APDU.Overrides java. Returns a string representation of this command APDU. |
| apdu | back to summary |
|---|---|
| private byte[] apdu | |
| dataOffset | back to summary |
|---|---|
| private transient int dataOffset | |
| MAX_APDU_SIZE | back to summary |
|---|---|
| private static final int MAX_APDU_SIZE | |
| nc | back to summary |
|---|---|
| private transient int nc | |
| ne | back to summary |
|---|---|
| private transient int ne | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| CommandAPDU | back to summary |
|---|---|
| public CommandAPDU(byte[] apdu) Constructs a CommandAPDU from a byte array containing the complete APDU contents (header and body). Note that the apdu bytes are copied to protect against subsequent modification.
| |
| CommandAPDU | back to summary |
|---|---|
| public CommandAPDU(byte[] apdu, int apduOffset, int apduLength) Constructs a CommandAPDU from a byte array containing the complete
APDU contents (header and body). The APDU starts at the index
Note that the apdu bytes are copied to protect against subsequent modification.
| |
| CommandAPDU | back to summary |
|---|---|
| public CommandAPDU(ByteBuffer apdu) Creates a CommandAPDU from the ByteBuffer containing the complete APDU
contents (header and body).
The buffer's Note that the data in the ByteBuffer is copied to protect against subsequent modification.
| |
| CommandAPDU | back to summary |
|---|---|
| public CommandAPDU(int cla, int ins, int p1, int p2) Constructs a CommandAPDU from the four header bytes. This is case 1 in ISO 7816, no command body.
| |
| CommandAPDU | back to summary |
|---|---|
| public CommandAPDU(int cla, int ins, int p1, int p2, int ne) Constructs a CommandAPDU from the four header bytes and the expected response data length. This is case 2 in ISO 7816, empty command data field with Ne specified. If Ne is 0, the APDU is encoded as ISO 7816 case 1.
| |
| CommandAPDU | back to summary |
|---|---|
| public CommandAPDU(int cla, int ins, int p1, int p2, byte[] data) Constructs a CommandAPDU from the four header bytes and command data.
This is case 3 in ISO 7816, command data present and Ne absent. The
value Nc is taken as data.length. If Note that the data bytes are copied to protect against subsequent modification.
| |
| CommandAPDU | back to summary |
|---|---|
| public CommandAPDU(int cla, int ins, int p1, int p2, byte[] data, int dataOffset, int dataLength) Constructs a CommandAPDU from the four header bytes and command data.
This is case 3 in ISO 7816, command data present and Ne absent. The
value Nc is taken as dataLength. If Note that the data bytes are copied to protect against subsequent modification.
| |
| CommandAPDU | back to summary |
|---|---|
| public CommandAPDU(int cla, int ins, int p1, int p2, byte[] data, int ne) Constructs a CommandAPDU from the four header bytes, command data,
and expected response data length. This is case 4 in ISO 7816,
command data and Ne present. The value Nc is taken as data.length
if Note that the data bytes are copied to protect against subsequent modification.
| |
| CommandAPDU | back to summary |
|---|---|
| public CommandAPDU(int cla, int ins, int p1, int p2, byte[] data, int dataOffset, int dataLength, int ne) Constructs a CommandAPDU from the four header bytes, command data,
and expected response data length. This is case 4 in ISO 7816,
command data and Le present. The value Nc is taken as
Note that the data bytes are copied to protect against subsequent modification.
| |
| arrayLength | back to summary |
|---|---|
| private static int arrayLength(byte[] b) | |
| checkArrayBounds | back to summary |
|---|---|
| private void checkArrayBounds(byte[] b, int ofs, int len) | |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Compares the specified object with this command APDU for equality. Returns true if the given object is also a CommandAPDU and its bytes are identical to the bytes in this CommandAPDU.
| |
| getBytes | back to summary |
|---|---|
| public byte[] getBytes() Returns a copy of the bytes in this APDU.
| |
| getCLA | back to summary |
|---|---|
| public int getCLA() Returns the value of the class byte CLA.
| |
| getData | back to summary |
|---|---|
| public byte[] getData() Returns a copy of the data bytes in the command body. If this APDU as no body, this method returns a byte array with length zero.
| |
| getINS | back to summary |
|---|---|
| public int getINS() Returns the value of the instruction byte INS.
| |
| getNc | back to summary |
|---|---|
| public int getNc() Returns the number of data bytes in the command body (Nc) or 0 if this
APDU has no body. This call is equivalent to
| |
| getNe | back to summary |
|---|---|
| public int getNe() Returns the maximum number of expected data bytes in a response APDU (Ne).
| |
| getP1 | back to summary |
|---|---|
| public int getP1() Returns the value of the parameter byte P1.
| |
| getP2 | back to summary |
|---|---|
| public int getP2() Returns the value of the parameter byte P2.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Returns the hash code value for this command APDU.
| |
| parse | back to summary |
|---|---|
| private void parse() Command APDU encoding options: case 1: |CLA|INS|P1 |P2 | len = 4 case 2s: |CLA|INS|P1 |P2 |LE | len = 5 case 3s: |CLA|INS|P1 |P2 |LC |...BODY...| len = 6..260 case 4s: |CLA|INS|P1 |P2 |LC |...BODY...|LE | len = 7..261 case 2e: |CLA|INS|P1 |P2 |00 |LE1|LE2| len = 7 case 3e: |CLA|INS|P1 |P2 |00 |LC1|LC2|...BODY...| len = 8..65542 case 4e: |CLA|INS|P1 |P2 |00 |LC1|LC2|...BODY...|LE1|LE2| len =10..65544 LE, LE1, LE2 may be 0x00. LC must not be 0x00 and LC1|LC2 must not be 0x00|0x00 | |
| readObject | back to summary |
|---|---|
| private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException | |
| setHeader | back to summary |
|---|---|
| private void setHeader(int cla, int ins, int p1, int p2) | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Returns a string representation of this command APDU.
| |