Smart Card Solution
User Manual
- R502 Manual
JavaCard API Samples
- Algorithm
Java Card Specification
Knowledge Sharing
Smart Card Solution
User Manual
JavaCard API Samples
Java Card Specification
Knowledge Sharing
This is an old revision of the document!
Field Summary | |
---|---|
static byte | PROTOCOL_MEDIA_CONTACTLESS_TYPE_A Transport protocol Media - Contactless Type A |
static byte | PROTOCOL_MEDIA_CONTACTLESS_TYPE_B Transport protocol Media - Contactless Type B |
static byte | PROTOCOL_MEDIA_DEFAULT Transport protocol Media - Contacted Asynchronous Half Duplex |
static byte | PROTOCOL_MEDIA_MASK Media nibble mask in protocol byte |
static byte | PROTOCOL_MEDIA_USB Transport protocol Media - USB |
static byte | PROTOCOL_T0 ISO 7816 transport protocol type T=0. |
static byte | PROTOCOL_T1 ISO 7816 transport protocol type T=1. |
static byte | PROTOCOL_TYPE_MASK Type nibble mask in protocol byte |
static byte | STATE_ERROR_IO This error state of a APDU object occurs when an APDUException with reason code APDUException.IO_ERROR has been thrown. |
static byte | STATE_ERROR_NO_T0_GETRESPONSE This error state of a APDU object occurs when an APDUException with reason code APDUException.NO_T0_GETRESPONSE has been thrown. |
static byte | STATE_ERROR_NO_T0_REISSUE This error state of a APDU object occurs when an APDUException with reason code APDUException.NO_T0_REISSUE has been thrown. |
static byte | STATE_ERROR_T1_IFD_ABORT This error state of a APDU object occurs when an APDUException with reason code APDUException.T1_IFD_ABORT has been thrown. |
static byte | STATE_FULL_INCOMING This is the state of a APDU object when all the incoming data been received. |
static byte | STATE_FULL_OUTGOING This is the state of a APDU object when all outbound data has been transferred. |
static byte | STATE_INITIAL This is the state of a new APDU object when only the command header is valid. |
static byte | STATE_OUTGOING This is the state of a new APDU object when data transfer mode is outbound but length is not yet known. |
static byte | STATE_OUTGOING_LENGTH_KNOWN This is the state of a APDU object when data transfer mode is outbound and outbound length is known. |
static byte | STATE_PARTIAL_INCOMING This is the state of a APDU object when incoming data has partially been received. |
static byte | STATE_PARTIAL_OUTGOING This is the state of a APDU object when some outbound data has been transferred but not all. |
Method Summary | |
---|---|
byte[] | getBuffer () Returns the APDU buffer byte array. |
static byte | getCLAChannel () Returns the logical channel number associated with the current APDU command based on the CLA byte. |
static APDU | getCurrentAPDU () This method is called during the Applet.process(APDU) method to obtain a reference to the current APDU object. |
static byte[] | getCurrentAPDUBuffer () This method is called during the Applet.process(APDU) method to obtain a reference to the current APDU buffer. |
byte | getCurrentState () This method returns the current processing state of the APDU object. |
static short | getInBlockSize () Returns the configured incoming block size. |
short | getIncomingLength () Returns the incoming data length(Lc). |
byte | getNAD () Returns the Node Address byte (NAD) in T=1 protocol, and 0 in T=0 protocol. |
short | getOffsetCdata () Returns the offset within the APDU buffer for incoming command data. |
static short | getOutBlockSize () Returns the configured outgoing block size. |
static byte | getProtocol () Returns the ISO 7816 transport protocol type, T=1 or T=0 in the low nibble and the transport media in the upper nibble in use. |
boolean | isCommandChainingCLA () Returns whether the current APDU command is the first or part of a command chain. |
boolean | isISOInterindustryCLA () Returns whether the current APDU command CLA byte corresponds to an interindustry command as defined in ISO 7816-4:2005 specification. |
boolean | isSecureMessagingCLA () Returns true if the encoding of the current APDU command based on the CLA byte indicates secure messaging. |
short | receiveBytes (short bOff) Gets as many data bytes as will fit without APDU buffer overflow, at the specified offset bOff. |
void | sendBytes (short bOff, short len) Sends len more bytes from APDU buffer at specified offset bOff. |
void | sendBytesLong (byte[] outData, short bOff, short len) Sends len more bytes from outData byte array starting at specified offset bOff. |
short | setIncomingAndReceive () This is the primary receive method. |
short | setOutgoing () This method is used to set the data transfer direction to outbound and to obtain the expected length of response (Le). |
void | setOutgoingAndSend (short bOff, short len) This is the “convenience” send method. |
void | setOutgoingLength (short len) Sets the actual length of response data. |
short | setOutgoingNoChaining () This method is used to set the data transfer direction to outbound without using BLOCK CHAINING (See ISO 7816-3/4) and to obtain the expected length of response (Le). |
static void | waitExtension () Requests additional processing time from CAD. |
Methods inherited from class java.lang.Object |
---|
equals |
Field Detail |
---|
public static final byte STATE_INITIAL
This is the state of a new APDU object when only the command header is valid.
See Also:Constant Field Values
public static final byte STATE_PARTIAL_INCOMING
This is the state of a APDU object when incoming data has partially been received.
See Also:Constant Field Values
public static final byte STATE_FULL_INCOMING
This is the state of a APDU object when all the incoming data been received.
See Also:Constant Field Values
public static final byte STATE_OUTGOING
This is the state of a new APDU object when data transfer mode is outbound but length is not yet known.
See Also:Constant Field Values
public static final byte STATE_OUTGOING_LENGTH_KNOWN
This is the state of a APDU object when data transfer mode is outbound and outbound length is known.
See Also:Constant Field Values
public static final byte STATE_PARTIAL_OUTGOING
This is the state of a APDU object when some outbound data has been transferred but not all.
See Also:Constant Field Values
public static final byte STATE_FULL_OUTGOING
This is the state of a APDU object when all outbound data has been transferred.
See Also:Constant Field Values
public static final byte STATE_ERROR_NO_T0_GETRESPONSE
This error state of a APDU object occurs when an APDUException with reason code APDUException.NO_T0_GETRESPONSE has been thrown.
See Also:Constant Field Values
public static final byte STATE_ERROR_T1_IFD_ABORT
This error state of a APDU object occurs when an APDUException with reason code APDUException.T1_IFD_ABORT has been thrown.
See Also:Constant Field Values
public static final byte STATE_ERROR_IO
This error state of a APDU object occurs when an APDUException with reason code APDUException.IO_ERROR has been thrown.
See Also:Constant Field Values
public static final byte STATE_ERROR_NO_T0_REISSUE
This error state of a APDU object occurs when an APDUException with reason code APDUException.NO_T0_REISSUE has been thrown.
See Also:Constant Field Values
public static final byte PROTOCOL_MEDIA_MASK
Media nibble mask in protocol byte
See Also:Constant Field Values
public static final byte PROTOCOL_TYPE_MASK
Type nibble mask in protocol byte
See Also:Constant Field Values
public static final byte PROTOCOL_T0
ISO 7816 transport protocol type T=0.
See Also:Constant Field Values
public static final byte PROTOCOL_T1
ISO 7816 transport protocol type T=1. This constant is also used to denote the T=CL variant for contactless cards defined in ISO14443-4.
See Also:Constant Field Values
public static final byte PROTOCOL_MEDIA_DEFAULT
Transport protocol Media - Contacted Asynchronous Half Duplex
See Also:Constant Field Values
public static final byte PROTOCOL_MEDIA_CONTACTLESS_TYPE_A
Transport protocol Media - Contactless Type A
See Also:Constant Field Values
public static final byte PROTOCOL_MEDIA_CONTACTLESS_TYPE_B
Transport protocol Media - Contactless Type B
See Also:Constant Field Values
public static final byte PROTOCOL_MEDIA_USB
Transport protocol Media - USB
See Also:Constant Field Values
Method Detail |
---|
public byte[] getBuffer()
Returns the APDU buffer byte array.
Note:
Returns:byte array containing the APDU buffer
public static short getInBlockSize()
Returns the configured incoming block size.
In T=1 protocol, this corresponds to IFSC (information field size for ICC),
the maximum size of incoming data blocks into the card. In T=0 protocol,
this method returns 1.
IFSC is defined in ISO 7816-3.
This information may be used to ensure that there is enough space remaining in the
APDU buffer when receiveBytes() is invoked.
Note:
Returns:incoming block size settingSee Also:receiveBytes(short)
public static short getOutBlockSize()
Returns the configured outgoing block size.
In T=1 protocol, this corresponds to IFSD (information field size for interface device),
the maximum size of outgoing data blocks to the CAD.
In T=0 protocol, this method returns 258 (accounts for 2 status bytes).
IFSD is defined in ISO 7816-3.
This information may be used prior to invoking the setOutgoingLength() method,
to limit the length of outgoing messages when BLOCK CHAINING is not allowed.
Note:
Returns:outgoing block size settingSee Also:setOutgoingLength(short)
public static byte getProtocol()
Returns the ISO 7816 transport protocol type, T=1 or T=0 in the low nibble and the transport media in the upper nibble in use.
Returns:the protocol media and type in progress Valid nibble codes are listed in PROTOCOL_* constants above. See PROTOCOL_T0 .
public byte getNAD()
Returns the Node Address byte (NAD) in T=1 protocol, and 0 in T=0 protocol. This may be used as additional information to maintain multiple contexts.
Returns:NAD transport byte as defined in ISO 7816-3
public short setOutgoing()
throws [[java-card-api:APDUException|APDUException]]
This method is used to set the data transfer direction to
outbound and to obtain the expected length of response (Le). This method
should only be called on a case 2 or case 4 command, otherwise erroneous
behavior may result.
Notes.
Returns:Le, the expected length of response
Throws:
APDUException - with the following reason codes:
public short setOutgoingNoChaining()
throws [[java-card-api:APDUException|APDUException]]
This method is used to set the data transfer direction to
outbound without using BLOCK CHAINING (See ISO 7816-3/4) and to obtain the expected length of response (Le).
This method should be used in place of the setOutgoing() method by applets which need
to be compatible with legacy CAD/terminals which do not support ISO 7816-3/4 defined block chaining.
See Runtime Environment
Specification for the Java Card Platform, section 9.4 for details.
Notes.
Returns:Le, the expected length of response data
Throws:
APDUException - with the following reason codes:
public void setOutgoingLength(short len)
throws [[java-card-api:APDUException|APDUException]]
Sets the actual length of response data. If a length of 0 is specified, no data will be output.
Note:
Parameters:len - the length of response data
Throws:
APDUException - with the following reason codes:
See Also:getOutBlockSize()
public short receiveBytes(short bOff)
throws [[java-card-api:APDUException|APDUException]]
Gets as many data bytes as will fit without APDU buffer overflow,
at the specified offset bOff. Gets all the remaining bytes if they fit.
Notes:
Parameters:bOff - the offset into APDU buffer
Returns:number of bytes read. Returns 0 if no bytes are available
Throws:
APDUException - with the following reason codes:
See Also:getInBlockSize()
public short setIncomingAndReceive()
throws [[java-card-api:APDUException|APDUException]]
This is the primary receive method.
Calling this method indicates that this APDU has incoming data. This method gets as many bytes
as will fit without buffer overflow in the APDU buffer following the header.
It gets all the incoming bytes if they fit. This method
should only be called on a case 3 or case 4 command, otherwise erroneous
behavior may result.
Notes:
Returns:number of data bytes read. The Le byte, if any, is not included in the count.
Returns 0 if no bytes are available.
Throws:
APDUException - with the following reason codes:
See Also:getIncomingLength() ,
getOffsetCdata()
public void sendBytes(short bOff,
short len) throws [[java-card-api:APDUException|APDUException]]
Sends len more bytes from APDU buffer at specified offset bOff.
If the last part of the response is being sent by the invocation
of this method, the APDU buffer must not be altered. If the data is altered, incorrect output may be sent to
the CAD.
Requiring that the buffer not be altered allows the implementation to reduce protocol overhead
by transmitting the last part of the response along with the status bytes.
Notes:
Parameters:bOff - the offset into APDU bufferlen - the length of the data in bytes to send
Throws:
APDUException - with the following reason codes:
See Also:setOutgoing() ,
setOutgoingNoChaining()
public void sendBytesLong(byte[] outData,
short bOff, short len) throws [[java-card-api:APDUException|APDUException]] , [[java-card-api:SecurityException|SecurityException]]
Sends len more bytes from outData byte array starting at specified offset
bOff. If the last of the response is being sent by the invocation
of this method, the APDU buffer must not be altered. If the data is altered, incorrect output may be sent to
the CAD.
Requiring that the buffer not be altered allows the implementation to reduce protocol overhead
by transmitting the last part of the response along with the status bytes.
The Java Card runtime environment may use the APDU buffer to send data to the CAD.
Notes:
Parameters:outData - the source data byte arraybOff - the offset into OutData arraylen - the byte length of the data to send
Throws:
SecurityException - if the outData array is not accessible in the caller's context
APDUException - with the following reason codes:
See Also:setOutgoing() ,
setOutgoingNoChaining()
public void setOutgoingAndSend(short bOff,
short len)
throws APDUException
This is the “convenience” send method. It provides for the most efficient way to send a short
response which fits in the buffer and needs the least protocol overhead.
This method is a combination of setOutgoing(), setOutgoingLength( len ) followed by
sendBytes ( bOff, len ). In addition, once this method is invoked, sendBytes() and
sendBytesLong() methods cannot be invoked and the APDU buffer must not be altered.
Sends len byte response from the APDU buffer starting at the specified offset bOff.
Notes:
Parameters:bOff - the offset into APDU bufferlen - the bytelength of the data to send
Throws:
APDUException - with the following reason codes:
public byte getCurrentState()
This method returns the current processing state of the APDU object. It is used by the BasicService class to help services collaborate in the processing of an incoming APDU command. Valid codes are listed in STATE_* constants above. See STATE_INITIAL .
Returns:the current processing state of the APDUSee Also:javacard.framework.service.BasicService
public static APDU getCurrentAPDU()
throws [[java-card-api:SecurityException|SecurityException]]
This method is called during the Applet.process(APDU) method
to obtain a reference to the current APDU object.
This method can only be called in the context of the currently
selected applet.
Note:
Returns:the current APDU object being processed
Throws:
SecurityException - if
public static byte[] getCurrentAPDUBuffer()
throws [[java-card-api:SecurityException|SecurityException]]
This method is called during the Applet.process(APDU) method
to obtain a reference to the current
APDU buffer.
This method can only be called in the context of the currently
selected applet.
Note:
Returns:the APDU buffer of the APDU object being processed
Throws:
SecurityException - if
public static byte getCLAChannel()
Returns the logical channel number associated with the current APDU command based on the CLA byte. A number in the range 0-19 based on the CLA byte encoding is returned if the command contains logical channel encoding. If the command does not contain logical channel information, 0 is returned. See Runtime Environment Specification for the Java Card Platform, section 4.3 for encoding details.
Returns:logical channel number, if present, within the CLA byte, 0 otherwise
public static void waitExtension()
throws [[java-card-api:APDUException|APDUException]]
Requests additional processing time from CAD. The implementation should ensure that this method
needs to be invoked only under unusual conditions requiring excessive processing times.
Notes:
Throws:
APDUException - with the following reason codes:
public boolean isCommandChainingCLA()
Returns whether the current APDU command is the first or part of a command chain. Bit b5 of the CLA byte if set, indicates that the APDU is the first or part of a chain of commands. See Runtime Environment Specification for the Java Card Platform, section 4.3 for encoding details.
Returns:true if this APDU is not the last APDU of a command chain, false otherwise.Since:
2.2.2
public boolean isSecureMessagingCLA()
Returns true if the encoding of the current APDU command based on the CLA byte indicates secure messaging. The secure messaging information is in bits (b4,b3) for commands with origin channel numbers 0-3, and in bit b6 for origin channel numbers 4-19. See Runtime Environment Specification for the Java Card Platform, section 4.3 for encoding details.
Returns:true if the secure messaging bit(s) is(are) nonzero, false otherwiseSince:
2.2.2
public boolean isISOInterindustryCLA()
Returns whether the current APDU command CLA byte corresponds to an interindustry command as defined in ISO 7816-4:2005 specification. Bit b8 of the CLA byte if 0, indicates that the APDU is an interindustry command.
Returns:true if this APDU CLA byte corresponds to an interindustry command, false otherwise.Since:
2.2.2
public short getIncomingLength()
Returns the incoming data length(Lc). This method can be invoked whenever inbound data processing methods can be invoked during case 1, 3 or 4 processing. It is most useful for an extended length enabled applet to avoid parsing the variable length Lc format in the APDU header.
Returns:the incoming byte length indicated by the Lc field in the APDU header.
Return 0 if no incoming data (Case 1)
Throws:
APDUException - with the following reason codes:
public short getOffsetCdata()
Returns the offset within the APDU buffer for incoming command data. This method can be invoked whenever inbound data processing methods can be invoked during case 1, 3 or 4 processing. It is most useful for an extended length enabled applet to avoid parsing the variable length Lc format in the APDU header.
Returns:the offset within the APDU buffer for incoming command data from the
previous call to setIncomingAndReceive() method. The
value returned is either 5 (Lc is 1 byte), or 7 (when Lc is 3 bytes)
Throws:
APDUException - with the following reason codes: