Java Reference
In-Depth Information
protocol:[slotid]; target
Each part is defined as follows:
protocol : Either apdu for an APDU-based connection (returning an object imple-
menting APDUConnection ) or jcrmi for a JCRMI-based connection (returning an
object implementing JavaCardRMIConnection )
slotid : An integer indicating the slot into which the user has inserted the card
target : The application identifier for the specific smart card application with which
to connect, or the word SAT to connect to a SIM application toolkit
Because devices can support more than one card slot, you can query smart
card-enabled hardware using the System.getProperty method with the microedition.
smartcardslots property, which returns a comma-delimited list of identifiers for existing
card slots. Each identifier consists of two characters: the first indicates the index you use
when specifying a URI to indicate the slot, and the second is either a C or an H indicating
whether the slot is cold-swappable or hot-swappable—that is, whether cards can only
be removed when the device is off (cold-swappable) or while the device is in operation
(hot-swappable).
Once you establish a connection to the smart card, you perform your I/O using the
exchangeAPDU method. Using exchangeAPDU , you send command APDUs to the smart card
and receive the response as an array of bytes. If necessary, you can establish several logi-
cal channels to the smart card using multiple APDUConnection instances, letting you use
more than one application on the smart card at a time. For example, you might write the
code shown in Listing 15-1.
Listing 15-1. Exchanging an APDU with a Smart Card
APDUConnection ac;
try {
byte[] commandAPDU = …;
String url = "apdu:0;AID=A1.0.0.67.4.7.1F.3.2C.5";
ac = (APDUConnection)Connector.open(url);
// Send a command APDU and receive a response APDU
byte[] responseAPDU = ac.exchangeAPDU(commandAPDU);
// Process the response
} catch(Exception e){
// Handle Exception
 
Search WWH ::




Custom Search