APDU Select 1

Dear,
I read an old discussion about the APDU Select and i tried to do the same without succed
My applet exist in digest directory, my class named Digest
I have the following code .scr
powerup;
// Select the installer applet
0x00 0xA4 0x04 0x00 0x09 0xa0 0x00 0x00 0x00 0x62 0x03 0x01 0x08 0x01 0x7F;
// 90 00 = SW_NO_ERROR
please help
Thank you
// Create an instance of the digest applet
0x80 0xB8 0x00 0x00 0x0a 0xa0 0x00 0x00 0x00 0x62 0x03 0x01 0x0c 0x04 0x01 0x7F;
// Select digest applet
0x00 0xA4 0x04 0x00 0x0a 0xa0 0x00 0x00 0x00 0x62 0x03 0x01 0x0c 0x04 0x01 0x7F;
powerdown;
and the out is:
CLA: 00, INS: a4, P1: 04, P2: 00, Lc: 09, a0, 00, 00, 00, 62, 03, 01, 08, 01, Le: 00, SW1: 90, SW2: 00
CLA: 80, INS: b8, P1: 00, P2: 00, Lc: 0a, a0, 00, 00, 00, 62, 03, 01, 0c, 04, 01, Le: 00, SW1: 64, SW2: 43
CLA: 00, INS: a4, P1: 04, P2: 00, Lc: 0a, a0, 00, 00, 00, 62, 03, 01, 0c, 04, 01, Le: 00, SW1: 6d, SW2: 00

Dear,
My question is not clear? Can I have a response, please?
I read the User's Guide and same problem exist.
Plz help me, I rely on you
Thx

Similar Messages

  • APDU SELECT communication on T=0, 1, CL

    Outside of the software simulation realm, I am trying to figure out what data communications look like on the low level serial channel when APDU SELECT is sent via T=0, T=1 or T=CL.
    I have reference material showing me the APDU (SELECT) packet format. Let's say a javacard is placed in the reader, and the terminal generates SELECT with a certain bytes sequence.
    Before being sent over the channel, is the byte sequence (packet) for SELECT encrypted?
    I had been skimming Global Platform and saw mention of the "secure channel" but don't understand where that comes into play. Is APDU SELECT wrapped within the secure channel and therefore encrypted?
    Before SELECT arrives, there is no active applet so I am trying to figure out who would do the encryption, and with what keys. Or am I missing a layer -- is in fact everything that goes over the physical serial channel encrypted, so no APDUs are ever in the clear?

    Outside of the software simulation realm, I am trying
    to figure out what data communications look like on
    the low level serial channel when APDU SELECT is sent
    via T=0, T=1 or T=CL.SELECT command itself for a Java Card / Global Platform card is described on the application layer in the corresponding specifications. On the low level only the protocol (T=0/1: ISO7816-3, T=CL: ISO14443) is described . The APDU structure is described in ISO7816-4. The commands described are not supported with the exception of the GET RESPONSE command (commands are defined in JC/GP).
    >
    I have reference material showing me the APDU
    (SELECT) packet format. Let's say a javacard is
    placed in the reader, and the terminal generates
    SELECT with a certain bytes sequence.
    Before being sent over the channel, is the byte
    sequence (packet) for SELECT encrypted?No. For a JC/GP card the SELECT command is never encrypted. It has a well defined structure.
    >
    I had been skimming Global Platform and saw mention
    of the "secure channel" but don't understand where
    that comes into play. Is APDU SELECT wrapped within
    the secure channel and therefore encrypted?
    Secure channel is used to establish a secured connection between the terminal and the card (Security Domain on-card). There are three levels of security (SCP01/02). First one is plain authentication, second is that a MAC is always added to every command (except SELECT, it closes a secure channel) after authentication, third one is that every command (exc. SELECT) is encrypted and MAC added after authentication.
    Before SELECT arrives, there is no active applet so I
    am trying to figure out who would do the encryption,
    and with what keys. Or am I missing a layer -- is in
    fact everything that goes over the physical serial
    channel encrypted, so no APDUs are ever in the clear?By default the so called CardManager is selected. It is possible to have a default selected Applet or a Supplementary Security Domain as well. The CardManager (on-card representative of the issuer, also called Issuer Security Domain) or a Supplementary SD is handling the secure channel, this would include encryption.

  • Session key and MAC generation in SCP '02' i='15'

    Hi,
    I am trying send a PUT KEY command and it resolves to '6982' after a '9000' EXTERNAL AUTHENTICATE.
    I suspect that my encryption is causing the problem.(not really sure!)
    I compare my session keys to some that ppl had derived and posted on the forum and I don't really get what they did.
    I am trying to find out if I'm deriving the correct session keys or not?!?!
    e.g
    //Calculating session keys with
    //static key = '404142434445464748494a4b4c4d4e4f' (keyData)
    //sequence counter = '003b'
    //"0101" + sequenceCounter + "000000000000000000000000" for session CMAC key (data)
    //"0102" + sequenceCounter + "000000000000000000000000" for session RMAC key (data)
    //"0181" + sequenceCounter + "000000000000000000000000" for session DEK key (data)
    //"0182" + sequenceCounter + "000000000000000000000000" for session ENC key (data)
    //sessionCMAC is :3213860da8f8d9796794cbcec43ef7a23213860da8f8d979: with sequence counter:003b (result)
    //sessionRMAC is :042a687f6e0dd3f80eabf1e5d51ccefe042a687f6e0dd3f8: with sequence counter:003b (result)
    //sessionDEK is :1fe31370c22354e3b90d6b8ad5686d371fe31370c22354e3: with sequence counter:003b (result)
    //sessionENC is :94a47ad54ffbf423fe4a9d915befab5294a47ad54ffbf423: with sequence counter:003b (result)
    <code>
    if (keyData.length == 16) {
    byte[] temp = (byte[]) keyData.clone();
    keyData = new byte[24];
    System.arraycopy(temp, 0, keyData, 0, temp.length);
    System.arraycopy(temp, 0, keyData, 16, 8);
    DESedeKeySpec keySpec = new DESedeKeySpec(keyData);
    SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance("DESede");
    SecretKey key = secretKeyFactory.generateSecret(keySpec);
    IvParameterSpec iv = new IvParameterSpec(new byte[]{0, 0, 0, 0, 0, 0, 0, 0});
    Cipher desedeCBCCipher = Cipher.getInstance("DESede/CBC/NoPadding");
    desedeCBCCipher.init(Cipher.ENCRYPT_MODE, key, iv);
    byte[] result = desedeCBCCipher.doFinal(data);
    if (result .length == 16) {
    byte[] temp = (byte[]) result .clone();
    result = new byte[24];
    System.arraycopy(temp, 0, result , 0, temp.length);
    System.arraycopy(temp, 0, result , 16, 8);
    keySpec = new DESedeKeySpec(result);
    secretKeyFactory = SecretKeyFactory.getInstance("DESede");
    key = secretKeyFactory.generateSecret(keySpec);
    </code>
    I use the same encrytion to derive KeyCheckValue with
    newKey ='505152535455565758595a5b5c5d5e5f', data = '0000000000000000'
    and it results to : '6d377e' (of course the last 3 bytes)
    Even though my CMAC session key is different from others (e.g "RLopes" in "http://192.9.162.102/thread.jspa?threadID=5365173&tstart=363" and I have seen it in others too and its really odd to me that its slightly different if you take a close look you will get what i mean) i get the EXTERNAL AUTHENTICATION to work.
    If there is anyone who is 100% sure meaning he/she got other commands to work after EXTERNAL AUTHENTICATE using CMAC please help me verify the keys I got?
    Can he/she test with his code to see if he/she is getting the same session keys or check value?
    Thanks in advance
    Kamran

    Hi,
    Here is the Class and thanks for the tip, I've honestly tried these <code></code> but didn't work and I know it is indeed annoying without the tags :D
    I really hope it helps...
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package terminalpcsc;
    import java.lang.Exception;
    import java.security.GeneralSecurityException;
    import java.security.Key;
    import java.security.SecureRandom;
    import java.util.List;
    import javax.crypto.*;
    import javax.crypto.spec.*;
    import javax.security.sasl.AuthenticationException;
    import javax.smartcardio.*;
    * @author Kamran
    * @param args the command line arguments
    public class Main {
        private static CardChannel channel;
        private static Card card;
        private static int CHALLENGE_LENGTH = 8;
        private static byte[] keyDiversification = new byte[10];
        private static byte[] keyInformation = new byte[2];
        private static byte[] sequenceCounter = new byte[2];
        private static byte[] cardChallenge = new byte[6];
        private static byte[] cardCryptogram = new byte[8];
        private static byte[] hostChallenge = new byte[8];
        private static byte[] hostCryptogram = new byte[8];
        private static String keyDiversificationHexString;
        private static String keyInformationHexString;
        private static String sequenceCounterHexString;
        private static String cardChallengeHexString;
        private static String cardCryptogramHexString;
        private static String hostChallengeHexString;
        private static String hostCryptogramHexString;
        private static byte[] sessionCMAC;
        private static byte[] sessionDEK;
        private static byte[] sessionENC;
        private static byte[] sessionRMAC;
        private static byte[] icvNextCommand;
        private static IvParameterSpec ivAllZeros = new IvParameterSpec(new byte[]{0, 0, 0, 0, 0, 0, 0, 0});
        private static byte[] staticKey = hexStringToByteArray("404142434445464748494a4b4c4d4e4f4041424344454647");
        private static byte[] newKey = hexStringToByteArray("505152535455565758595a5b5c5d5e5f");
        private static byte[] CMAC;
         * @param args the command line arguments
        public static void main(String[] args) throws Exception {
            initiateCardChannel();
            String apduString = generateSelectAPDU("a000000003535041");
            byte[] bufferC = hexStringToByteArray(apduString);
            CommandAPDU capdu = new CommandAPDU(bufferC);
            System.out.println("Sending APDU Select AID: " + byteArrayToHexString(bufferC));
            ResponseAPDU rapdu = channel.transmit(capdu);
            System.out.println("Sending Apdu: Done!");
            System.out.println("Waiting For Response...");
            byte[] bufferR = rapdu.getData();
            String responseData = byteArrayToHexString(rapdu.getBytes());
            System.out.println("Response: " + responseData);
            apduString = generateInitializeUpdateAPDU();
            bufferC = hexStringToByteArray(apduString);
            capdu = new CommandAPDU(bufferC);
            System.out.println("Sending APDU Initialize Update: " + byteArrayToHexString(bufferC));
            rapdu = channel.transmit(capdu);
            System.out.println("Sending Apdu: Done!");
            System.out.println("Waiting For Response...");
            bufferR = rapdu.getData();
            responseData = byteArrayToHexString(rapdu.getBytes());
            System.out.println("Response: " + responseData);
            // protocol 01
            //System.arraycopy(bufferR,0,keyDiversification,0,10);
            //System.arraycopy(bufferR,10,keyInformation,0,2);
            //System.arraycopy(bufferR,12,cardChallenge,0,8);
            //System.arraycopy(bufferR,20,cardCryptogram,0,8);
            // protocol 02
            System.arraycopy(bufferR, 0, keyDiversification, 0, 10);
            System.arraycopy(bufferR, 10, keyInformation, 0, 2);
            System.arraycopy(bufferR, 12, sequenceCounter, 0, 2);
            System.arraycopy(bufferR, 14, cardChallenge, 0, 6);
            System.arraycopy(bufferR, 20, cardCryptogram, 0, 8);
            keyDiversificationHexString = byteArrayToHexString(keyDiversification);
            keyInformationHexString = byteArrayToHexString(keyInformation);
            sequenceCounterHexString = byteArrayToHexString(sequenceCounter);
            cardChallengeHexString = byteArrayToHexString(cardChallenge);
            cardCryptogramHexString = byteArrayToHexString(cardCryptogram);
            System.out.println("keyDiversification: " + keyDiversificationHexString);
            System.out.println("keyInformation: " + keyInformationHexString);
            System.out.println("sequenceCounter: " + sequenceCounterHexString);
            System.out.println("cardChallenge: " + cardChallengeHexString);
            System.out.println("cardCryptogram: " + cardCryptogramHexString);
            System.out.println("Calculating Session Keys... encryption with CBC");
            //E.4.1 GP 2.1.1
            sessionCMAC = deriveEncryptionCBC(staticKey, hexStringToByteArray("0101" + sequenceCounterHexString + "000000000000000000000000"));
            System.out.println("sessionCMAC is :" + byteArrayToHexString(sessionCMAC) + ": with sequence counter:" + sequenceCounterHexString);
            sessionRMAC = deriveEncryptionCBC(staticKey, hexStringToByteArray("0102" + sequenceCounterHexString + "000000000000000000000000"));
            System.out.println("sessionRMAC is :" + byteArrayToHexString(sessionRMAC) + ": with sequence counter:" + sequenceCounterHexString);
            sessionDEK = deriveEncryptionCBC(staticKey, hexStringToByteArray("0181" + sequenceCounterHexString + "000000000000000000000000"));
            System.out.println("sessionDEK is :" + byteArrayToHexString(sessionDEK) + ": with sequence counter:" + sequenceCounterHexString);
            sessionENC = deriveEncryptionCBC(staticKey, hexStringToByteArray("0182" + sequenceCounterHexString + "000000000000000000000000"));
            System.out.println("sessionENC is :" + byteArrayToHexString(sessionENC) + ": with sequence counter:" + sequenceCounterHexString);
            System.out.println("Calculating and Verifying Card Cryptogram...");
            byte[] signature = cbcMACSignature(hexStringToByteArray(hostChallengeHexString + sequenceCounterHexString + cardChallengeHexString + "8000000000000000"), sessionENC);
            String signatureHexString = byteArrayToHexString(signature);
            if (signatureHexString.equalsIgnoreCase(cardCryptogramHexString)) {
                System.out.println("signature is :" + signatureHexString + "\ncardCryptogram is :" + cardCryptogramHexString + " \nCard cryptogram authenticated");
                apduString = generateExternalAuthenticateAPDU();
                bufferC = hexStringToByteArray(apduString);
                capdu = new CommandAPDU(bufferC);
                System.out.println("Sending APDU External Authenticate: " + byteArrayToHexString(bufferC));
                rapdu = channel.transmit(capdu);
                System.out.println("Sending Apdu: Done!");
                System.out.println("Waiting For Response...");
                bufferR = rapdu.getData();
                responseData = byteArrayToHexString(rapdu.getBytes());
                System.out.println("Response: " + responseData);
                apduString = generatePutKeyAPDU();
                bufferC = hexStringToByteArray(apduString);
                capdu = new CommandAPDU(bufferC);
                System.out.println("Sending APDU Put Key: " + byteArrayToHexString(bufferC));
                rapdu = channel.transmit(capdu);
                System.out.println("Sending Apdu: Done!");
                System.out.println("Waiting For Response...");
                bufferR = rapdu.getData();
                responseData = byteArrayToHexString(rapdu.getBytes());
                System.out.println("Response: " + responseData);
            } else {
                System.out.println("signature is :" + signatureHexString + "\ncardCryptogram is :" + cardCryptogramHexString + " \nCard cryptogram is not authenticated");
            releaseCardChannel();
        public static byte[] cbcMACSignature(byte[] data, byte[] sessionSENC) throws AuthenticationException {
            IvParameterSpec params =
                    new IvParameterSpec(new byte[]{0, 0, 0, 0, 0, 0, 0, 0});
            if (sessionSENC.length == 16) {
                byte[] temp = (byte[]) sessionSENC.clone();
                sessionSENC = new byte[24];
                System.arraycopy(temp, 0, sessionSENC, 0, temp.length);
                System.arraycopy(temp, 0, sessionSENC, 16, 8);
            byte[] temp = null;
            SecretKey secretKey = new SecretKeySpec(sessionSENC, "DESede");
            try {
                Cipher cbcDES = Cipher.getInstance("DESede/CBC/NoPadding");
                cbcDES.init(Cipher.ENCRYPT_MODE, secretKey, params);
                temp = cbcDES.doFinal(data);
            } catch (GeneralSecurityException e) {
                e.printStackTrace();
            byte[] signature = new byte[8];
            System.arraycopy(temp, temp.length - 8, signature, 0, signature.length);
            return signature;
        // generateInitialUpdateAPDU()
        //CLA '80'
        //INS '50' INITIALIZE UPDATE
        //P1 'xx' Key Version Number
        //P2 '00' Reference control parameter P2
        //Lc '08' Length of host challenge
        //Data 'xx xx…' Host challenge
        //Le '00'
        //RESPONSE TEMPLATE
        //Key diversification data 10 bytes
        //Key information 2 bytes
        //Card challenge 8 bytes
        //Card cryptogram 8 bytes
        public static String generateInitializeUpdateAPDU() throws Exception {
            hostChallenge = generateHostChallenge();
            hostChallengeHexString = byteArrayToHexString(hostChallenge);
            return "8050000008" + hostChallengeHexString + "00";
        //CLA '80' or '84'
        //INS 'D8' PUT KEY
        //P1 'xx' Reference control parameter P1 Key Version Number -- '00' is new key  range is '01' to '7F'
        //P2 'xx' Reference control parameter P2 Key Identifier     -- '00' to '7F'
        //Lc 'xx' Length of data field
        //Data 'xxxx..' Key data (and MAC if present)
        //Le '00'
        public static String generatePutKeyAPDU() throws Exception {
            String keyCheckValue = new String();
            //keyCheckValue = keyCheckValue.substring(keyCheckValue.length() - (3 * 2));
            keyCheckValue = byteArrayToHexString(deriveEncryptionECB(newKey, hexStringToByteArray("0000000000000000")));
            keyCheckValue = keyCheckValue.substring(keyCheckValue.length() - (3 * 2));
            System.out.println("keyCheckValue :" + keyCheckValue + " 3DES ECB, key is new key '505152535455565758595a5b5c5d5e5f5051525354555657', data is 8 zeroes");
            String encryptedNewKey = byteArrayToHexString(deriveEncryptionECB(sessionDEK, newKey));
            //System.out.println("sessionDEK.getEncoded() :" + sessionDEK.getEncoded() + " len is:" + sessionDEK.getEncoded().length);
            System.out.println("encryptedNewKey :" + encryptedNewKey);
            //testing newKey
            String dataField = "01" + "8010" + encryptedNewKey + "03" + keyCheckValue + "8010" + encryptedNewKey + "03" + keyCheckValue + "8010" + encryptedNewKey + "03" + keyCheckValue;
            // String dataField2 = "01" + "8010" + byteArrayToHexString(newKey) + "03" + keyCheckValue + "8010" + byteArrayToHexString(newKey) + "03" + keyCheckValue + "8010" + byteArrayToHexString(newKey) + "03" + keyCheckValue;
            System.out.println("datafield to calculate cmac :" + dataField);
            System.out.println("icv to calculate cmac is previous mac first 8 byte sessionCMAC in CBC single des :" + byteArrayToHexString(icvNextCommand));
            CMAC = generateCMac2((byte) 0x84, (byte) 0xD8, (byte) 0x00, (byte) 0x81, hexStringToByteArray(dataField), sessionCMAC, icvNextCommand);
            System.out.println("data field with des padding for encryption (encryption in CBC sessionENC) :" + desPadding(dataField));
            String dataField3 = byteArrayToHexString(deriveEncryptionCBC(sessionENC, hexStringToByteArray(desPadding(dataField))));
            System.out.println("data field after encryption :" + dataField3);
            Integer CMACLen = byteArrayToHexString(CMAC).length() / 2;
            System.out.println("CMACLen :" + CMACLen);
            Integer dataFieldLen = dataField3.length() / 2;
            System.out.println("dataFieldLen :" + dataFieldLen);
            Integer intLc = dataFieldLen + CMACLen;
            System.out.println("intLc :" + intLc);
            String hexLc = Integer.toString(intLc, 16);
            System.out.println("hexLc :" + hexLc);
            return "84D80081" + hexLc + dataField3 + byteArrayToHexString(CMAC) + "00";
        //generateExternalAuthenticateAPDU()
        //CLA '84'
        //INS '82' EXTERNAL AUTHENTICATE
        //P1 'xx' Security level  --'03' C-DECRYPTION and C-MAC.--'01' C-MAC.'00' No secure messaging expected.
        //P2 '00' Reference control parameter P2
        //Lc '10' Length of host cryptogram and MAC
        //Data 'xx xx…' Host cryptogram and MAC
        //Le Not present
        public static String generateExternalAuthenticateAPDU() throws Exception {
            System.out.println("Calculating and Verifying Host Cryptogram...");
            hostCryptogram = cbcMACSignature(hexStringToByteArray(sequenceCounterHexString + cardChallengeHexString + hostChallengeHexString + "8000000000000000"), sessionENC);
            hostCryptogramHexString = byteArrayToHexString(hostCryptogram);
            System.out.println("hostCryptogram is :" + hostCryptogramHexString);
            CMAC = generateCMac2((byte) 0x84, (byte) 0x82, (byte) 0x03, (byte) 0x00, hostCryptogram, sessionCMAC, new byte[]{0, 0, 0, 0, 0, 0, 0, 0});
            return "8482030010" + hostCryptogramHexString + byteArrayToHexString(CMAC);
        // generateSelectAPDU()
        //CLA '00' ISO/IEC 7816-4 command
        //INS 'A4' SELECT
        //P1 'xx' Reference control parameter P1 --'04' select by name
        //P2 'xx' Reference control parameter P2 --'00' First or only occurrence --'02' Next occurrence
        //Lc 'xx' Length of AID
        //Data 'xxxx..' AID of Application to be selected
        //Le '00'
        // RESPONSE TEMPLATE
        //'6F' File Control Information (FCI template) Mandatory
        //'84' Application / file AID Mandatory
        //'A5' Proprietary data Mandatory
        //'73' Security Domain Management Data (see Appendix F for detailed coding) Optional
        //'9F6E' Application production life cycle data Optional
        //'9F65' Maximum length of data field in command message Mandatory
        public static String generateSelectAPDU(String AID) throws Exception {
            String AIDlen = Integer.toString(AID.length() / 2, 16);
            if (AIDlen.length() == 1) {
                AIDlen = "0" + AIDlen;
            System.out.println("00A40400" + AIDlen + AID);
            return "00A40400" + AIDlen + AID;
        public static String byteArrayToHexString(byte[] b) throws Exception {
            String result = "";
            for (int i = 0; i < b.length; i++) {
                result +=
                        Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1);
            return result;
        public static void initiateCardChannel() throws CardException {
            System.out.println("Connecting to Java Card...");
            TerminalFactory factory = TerminalFactory.getDefault();
            List<CardTerminal> terminals = factory.terminals().list();
            System.out.println("Terminals Detected: " + terminals);
            // get the first terminal
            System.out.println("Connecting to: " + terminals + "...");
            CardTerminal terminal = terminals.get(0);
            System.out.println("Connected to: " + terminals);
            // establish a connection with the card
            System.out.println("Connecting to Java Card...");
            card = terminal.connect("T=0");
            System.out.println("Connected to card: " + card);
            System.out.println("Obtaining Channel...");
            channel = card.getBasicChannel();
            System.out.println("Connecting to Channel: " + channel.getChannelNumber());
        public static void releaseCardChannel() throws CardException {
            System.out.println("Disconnection all...");
            card.disconnect(false);
            System.out.println("Disconnection Done");
            System.out.println("*END*");
        public static byte[] hexStringToByteArray(String s) {
            int len = s.length();
            byte[] data = new byte[len / 2];
            for (int i = 0; i < len; i += 2) {
                data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16));
            return data;
        //To generate the derivation data:
        public static byte[] deriveEncryptionCBC(byte[] keyData, byte[] data) throws GeneralSecurityException {
            //Key key = getSecretKey(keyData);
            if (keyData.length == 16) {
                byte[] temp = (byte[]) keyData.clone();
                keyData = new byte[24];
                System.arraycopy(temp, 0, keyData, 0, temp.length);
                System.arraycopy(temp, 0, keyData, 16, 8);
            SecretKey secretKey = new SecretKeySpec(keyData, "DESede");
            IvParameterSpec dps =
                    new IvParameterSpec(new byte[]{0, 0, 0, 0, 0, 0, 0, 0});
            String algorithm = "DESede/CBC/NoPadding";
            Cipher desedeCBCCipher = Cipher.getInstance(algorithm);
            desedeCBCCipher.init(Cipher.ENCRYPT_MODE, secretKey, dps);
            byte[] result = desedeCBCCipher.doFinal(data);
            //adjustParity(result);
            return result;
        public static byte[] deriveEncryptionECB(byte[] keyData, byte[] data) throws GeneralSecurityException {
            //Key key = getSecretKey(keyData);
            if (keyData.length == 16) {
                byte[] temp = (byte[]) keyData.clone();
                keyData = new byte[24];
                System.arraycopy(temp, 0, keyData, 0, temp.length);
                System.arraycopy(temp, 0, keyData, 16, 8);
            SecretKey secretKey = new SecretKeySpec(keyData, "DESede");
            String algorithm = "DESede/ECB/NoPadding";
            Cipher desedeCBCCipher = Cipher.getInstance(algorithm);
            desedeCBCCipher.init(Cipher.ENCRYPT_MODE, secretKey);
            byte[] result = desedeCBCCipher.doFinal(data);
            //adjustParity(result);
            return result;
         * Adjust a DES key to odd parity
         * @param key
         *            to be adjusted
        public static byte[] adjustParity(byte[] key) {
            for (int i = 0; i < key.length; i++) {
                int akku = (key[i] & 0xFF) | 1;
                for (int c = 7; c > 0; c--) {
                    akku = (akku & 1) ^ (akku >> 1);
                key[i] = (byte) ((key[i] & 0xFE) | akku);
            return key;
        public static byte[] generateCMac2(byte cla, byte ins, byte p1, byte p2, byte[] dataField, byte[] SMacSessionKey, byte[] icv) throws GeneralSecurityException, Exception {
            if (SMacSessionKey.length == 16) {
                byte[] temp = (byte[]) SMacSessionKey.clone();
                SMacSessionKey = new byte[24];
                System.arraycopy(temp, 0, SMacSessionKey, 0, temp.length);
                System.arraycopy(temp, 0, SMacSessionKey, 16, 8);
            byte[] cMac = new byte[8];
            byte[] padding = {(byte) 0x80, 0, 0, 0, 0, 0, 0, 0};
            int paddingRequired = 8 - (5 + dataField.length) % 8;
            byte[] data = new byte[5 + dataField.length + paddingRequired];
            //Build APDU
            data[0] = cla;
            data[1] = ins;
            data[2] = p1;
            data[3] = p2;
            data[4] = (byte) ((byte) dataField.length + (byte) 0x08);
            System.arraycopy(dataField, 0, data, 5, dataField.length);
            System.arraycopy(padding, 0, data, 5 + dataField.length, paddingRequired);
            System.out.println("data to calculate mac :" + byteArrayToHexString(data));
            System.out.println("icv to calculate mac :" + byteArrayToHexString(icv));
            Cipher cipher = Cipher.getInstance("DESede/CBC/NoPadding");
            Cipher singleDesCipher = Cipher.getInstance("DES/CBC/NoPadding", "SunJCE");
            SecretKeySpec desSingleKey = new SecretKeySpec(SMacSessionKey, 0, 8, "DES");
            SecretKey secretKey = new SecretKeySpec(SMacSessionKey, "DESede");
            //Calculate the first n - 1 block. For this case, n = 1
            IvParameterSpec ivSpec = new IvParameterSpec(icv);
            singleDesCipher.init(Cipher.ENCRYPT_MODE, desSingleKey, ivSpec);
            byte ivForLastBlock[] = singleDesCipher.doFinal(data, 0, 8);
            int blocks = data.length / 8;
            for (int i = 0; i < blocks - 1; i++) {
                singleDesCipher.init(Cipher.ENCRYPT_MODE, desSingleKey, ivSpec);
                byte[] block = singleDesCipher.doFinal(data, i * 8, 8);
                ivSpec = new IvParameterSpec(block);
            int offset = (blocks - 1) * 8;
            cipher.init(Cipher.ENCRYPT_MODE, secretKey, ivSpec);
            cMac = cipher.doFinal(data, offset, 8);
            ivSpec = new IvParameterSpec(new byte[8]);
            singleDesCipher.init(Cipher.ENCRYPT_MODE, desSingleKey, ivSpec);
            icvNextCommand = singleDesCipher.doFinal(cMac);
            return cMac;
        public static byte[] generateHostChallenge() {
            byte[] hostChallenge = new byte[CHALLENGE_LENGTH];
            SecureRandom random = new SecureRandom();
            random.nextBytes(hostChallenge);
            return hostChallenge;
        public static String desPadding(String hexString) {
            System.out.println("String to pad before:" + hexString);
            hexString = hexString + "80";
            int hexStringLen = hexString.length() / 2;
            int padding = 8 - (hexStringLen % 8);
            for (int i = 0; i < padding; i++) {
                hexString = hexString + "00";
            System.out.println("String to pad after :" + hexString);
            return hexString;
    }Thanks in advance
    Kamran

  • How to ensure applet is written in java card?

    Hi all,
    I have written a java card applet, in which i am using the Biometry API of java card to enroll a fingerprint template in java card. Code is attached below:
    package classicapplet1;
    import javacard.framework.*;
    import javacardx.biometry.BioBuilder;
    import javacardx.biometry.OwnerBioTemplate;
    import javacardx.biometry.SharedBioTemplate;
    import javacardx.biometry.BioException;
    public class JavaBiometrics extends Applet implements SharedBioTemplate{
            public final static byte CLA = (byte)0xCF;
         public final static byte INS_ENROLL = (byte)0x10;
         public final static byte MATCH_TRY_LIMIT = (byte)3;
         public final static byte INVALID_DATA = (byte)0x77;
         public final static byte ERROR_MATCH_FAILED = (byte)0x9101;
         public static final byte CARD_ENROLL_SUCCESS = (byte)0x9000;
         public static final byte CARD_ENROL_FAILED = (byte)0x6900;
         private OwnerBioTemplate bio_temp;
         * Installs this applet.
         * @param bArray
         *            the array containing installation parameters
         * @param bOffset
         *            the starting offset in bArray
         * @param bLength
         *            the length in bytes of the parameter data in bArray
        public static void install(byte[] bArray, short bOffset, byte bLength) {
            new JavaBiometrics(bArray, bOffset, bLength);
         * Only this class's install method should create the applet object.
        protected JavaBiometrics(byte[] bArray, short bOffset, short bLength) {
        byte aidLen = bArray[bOffset];
              if(aidLen == (byte)0)
                   register();
              else
                   register(bArray, (short)(bOffset+1), aidLen);
              bio_temp = BioBuilder.buildBioTemplate(BioBuilder.FINGERPRINT, MATCH_TRY_LIMIT);
    public boolean select()
    return true;
         * Processes an incoming APDU.
         * @see APDU
         * @param apdu
         *            the incoming APDU
        public void process(APDU apdu) {
            //get the incoming APDU buffer
         byte []buffer = apdu.getBuffer();
         //Get the CLA; mask out the logical-channel info
         buffer[ISO7816.OFFSET_CLA] = (byte)(buffer[ISO7816.OFFSET_CLA] & (byte)0xFC);
         //If the INS Select, return -no need to process select
         if(buffer[ISO7816.OFFSET_CLA] == 0 && buffer[ISO7816.OFFSET_INS] == (byte)(0xA4))
              return;
         //If unrecognized class, return "Unsupported class."
         if(buffer[ISO7816.OFFSET_CLA] != CLA)
              ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
         switch(buffer[ISO7816.OFFSET_INS])
         case INS_ENROLL:
              enroll(apdu);
              break;
         default:
              ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
    public void enroll(APDU apdu)
            byte[] buffer = apdu.getBuffer();
            short bytesRead = apdu.setIncomingAndReceive();
            bio_temp.init(buffer, ISO7816.OFFSET_CDATA, bytesRead);
            bio_temp.doFinal();
        public Shareable getShareableInterfaceObject(AID clientAID, byte parameter) {
            return this;
    ///////////// These methods implemets the ShareableBio interface///////////////
    public boolean isInitialized() {
            return bio_temp.isInitialized();
        public boolean isValidated() {
            return bio_temp.isValidated();
        public void reset() {
            bio_temp.reset();
        public byte getTriesRemaining() {
            return bio_temp.getTriesRemaining();
        public byte getBioType() {
            return bio_temp.getBioType();
        public short getVersion(byte[] dest, short offset) {
            return bio_temp.getVersion(dest, offset);
        public short getPublicTemplateData(short publicOffset, byte[] dest, short destOffset, short length)
                throws BioException {
            return bio_temp.getPublicTemplateData(publicOffset, dest, destOffset, length);
        public short initMatch(byte[] candidate, short offset, short length) throws BioException {
            return bio_temp.initMatch(candidate, offset, length);
        public short match(byte[] candidate, short offset, short length) throws BioException {
            return bio_temp.match(candidate, offset, length);
    Problem :
    I have developed this program in Netbeans using java card plug ins. when i am running this program, all the required CAP files and EXP files are generated.
    Now, i have to write this applet on java card through a card reader. My card reader is installed in an embedded system GeoAmida with IP 192.133.133.2 and port number 6789.
    I have used the following settings for my java card device in Netbeans:
    Host : 192.133.133.2
    Server URL: http://192.133.133.2:6789/
    Card Manager URL: http://192.133.133.2:6789/cardmanager/
    HTTP port: 6789
    The output shows me that Instances of this program has been successfully has been created on java card.
    But the problem is how can i ensure that my applet is been successfully installed on the java card?
    The code of host application program, accessing the developed java card applet is given below (it is written in C):
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <smartcard.h>
    int main()
         int ret, i, smartcard;
         unsigned char applet_id[100], apdu_len, apdu[300],response[300]={0};
         smartcard_info *context;
         smartcard=CONTACTLESS;
         //smartcard=CONTACT_BOT;
         if((context = smartcard_init(smartcard)) == NULL){
              printf("Smartcard Initi. Failed\n");
              return 0xBB;
         /* checking for smartcard */
         while (1){
              if(ret=smartcard_is_present(context, smartcard)!=0)
                   sleep(1);
              else
                   break;
         printf("Selecting Applet \n");
         i = 0;
         applet_id[i++]=0x00; applet_id[i++]=0xA4; applet_id[i++]=0x04; applet_id[i++]=0x00; applet_id[i++]=0x06;
         applet_id[i++]=0xA9; applet_id[i++]=0xBF; applet_id[i++]=0xA2; applet_id[i++]=0xB6; applet_id[i++]=0xB1; applet_id[i++]=0x3E; applet_id[i++]=0x7F;
         if ((ret=smartcard_select_applet(context, smartcard, applet_id, i))!=0){
              printf("select applet failed %02x\n",ret);
              return ;
         printf("Applet Selection Success \n");
    #if 1
         i=0;
         apdu[i++]=0xCF; apdu[i++]=0x10; apdu[i++]=0x04; apdu[i++]=0x04; apdu[i++]=0x7F;
         //apdu[i++]=0x3F; apdu[i++]=0x00;
         apdu_len = i;
         printf("Sending APDU command\n");
         if ((ret=smartcard_apdu(context, smartcard, apdu, apdu_len, response))!=0){
              printf("apdu failed %d\n",ret);
              //return;
         }else
              printf("APDU Success\n");
         //printf("\n");
    #endif
         smartcard_deinit(context);
         return 0;     
    }The output of this program is showing me that applet is been successfully selected, but APDU selection failed. Please solve this problem as soon as possible, because my project is deadline is not very much far.
    Thanks in advance.
    Mukul Gupta

    Hi Shane,
    I am getting error 6a86 which means that value of P1 is less than 1 or more than 8, and we have to change its value to any in between 1 to 8. I did that also but error still remains :(
    Please tell me what is reason behind this error. And, i'll try out your previous solution today, Thanks for it.

  • Help me solve this problem, Urgent. Thx

    I am new in javacard.
    I wrote a javacard applet and loaded applet into card using JCOP successfull.
    My card applet:
    package stAppletTest;
    import javacard.framework.APDU;
    import javacard.framework.Applet;
    import javacard.framework.ISO7816;
    import javacard.framework.ISOException;
    public class STAppletTest extends Applet {
         final static byte demo_cla = (byte)0x80;
         final static byte SetStr = (byte)0x10;
         final static byte GetStr = (byte)0x20;
         byte[] oldStr;
         byte[] newStr;
         private STAppletTest(byte[] bArr, short bOff, byte l)
              oldStr= new byte[100];
              newStr= new byte[100];
              if (bArr[bOff]==(byte)0)
                   register();
              else register(bArr, (short)(bOff+1) ,(byte)(bArr[bOff]));
         public static void install(byte[] bArray, short bOffset, byte bLength) {
              // GP-compliant JavaCard applet registration
              new STAppletTest(bArray, (short) (bOffset + 1),
                        bArray[bOffset]);
         public void process(APDU apdu) {
              // Good practice: Return 9000 on SELECT
              if (selectingApplet()) {
                   return;
              byte[] buf = apdu.getBuffer();
              byte cla=buf[ISO7816.OFFSET_CLA];
              if (cla!=demo_cla) ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
              switch (buf[ISO7816.OFFSET_INS]) {
              case (byte) 0x00:
                   break;
              case SetStr:
                    SetString(apdu);
                    break;
              case GetStr:
                    GetString(apdu);
                    break;
              default:
                   // good practice: If you don't know the INStruction, say so:
                   ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
         private void SetString(APDU apdu)
              byte buffer[] = apdu.getBuffer();
              byte size = (byte)(apdu.setIncomingAndReceive());
              byte i;
              //  Store the length of the string and the string itself
              oldStr[0] = size;
              for (i = 0; i< size; i++)
                   oldStr[(byte)(i+1)] = buffer[(byte)(ISO7816.OFFSET_CDATA+i)];
              return;
         private byte[] GetString(APDU apdu)     {
              byte buffer1[] = apdu.getBuffer();
              byte numBytes = buffer1[ISO7816.OFFSET_LC];
              if (numBytes == (byte)0) {
                   ISOException.throwIt((short)(0x6200));
              apdu.setOutgoing();
              apdu.setOutgoingLength(numBytes);                    
              byte index;
              for (index = 0; index <= numBytes; index++)
                   buffer1[index] = oldStr[(byte)(index + 1)];
              return buffer1;
    }and my code to communicate with card:
    import java.util.*;
    import opencard.core.service.*;
    import opencard.core.terminal.*;
    import opencard.opt.util.*;
    public class STTerminalTest {
      private static final int IFD_TIMEOUT = 10;     // unit: seconds
      private static final int MAX_APDU_SIZE = 100;  // unit: byte 
      final byte[] CMD_SELECT_APPLET = {(byte)0x00, (byte)0xA4,
                                    (byte)0x00, (byte)0x00, (byte)0x06,
                                    (byte)0x00, (byte)0x01, (byte)0x02, (byte)0x03, (byte)0x04, (byte)0x05 };
      final byte[] CMD_SET_STRING ={(byte)0x80, (byte)0x10,
                                       (byte)0x00, (byte)0x00, (byte)0x02,
                                       (byte)0x00, (byte)0x01 };
      final byte[] CMD_READ_STRING ={(byte)0x80, (byte)0x20,
                                     (byte)0x00, (byte)0x00, (byte)0x02 };
      private int n, x;
      private byte[] i;
      public STTerminalTest() {
        // create system properties object
        Properties sysProps = System.getProperties();
        // set system properties for OCF, PC/SC and PassThruCardServce
        sysProps.put ("OpenCard.terminals", "com.ibm.opencard.terminal.pcsc10.Pcsc10CardTerminalFactory");
        sysProps.put ("OpenCard.services", "opencard.opt.util.PassThruCardServiceFactory");
      public void runExample() {
        try {
          System.out.println("activate Smart Card");
          SmartCard.start();  // activate smart card
          CardRequest cr = new CardRequest(CardRequest.ANYCARD, null, PassThruCardService.class);
          cr.setTimeout(IFD_TIMEOUT);  // set timeout for IFD
          // wait  for a smart card inserted into the terminal
          System.out.println("wait for smart card - insert smart card in terminal");
          SmartCard sc = SmartCard.waitForCard(cr);
          if (sc != null) {  // no error occur and a smart card is in the terminal
            PassThruCardService ptcs = (PassThruCardService) sc.getCardService(PassThruCardService.class, true);
            System.out.print("Card ATR:           ");
            CardID cardID = sc.getCardID ();
            i = cardID.getATR();
            String s = new String();
            for (n = 0; n < i.length; n++) {
              x = (int) (0x000000FF & i[n]);  // byte to int conversion
              s = Integer.toHexString(x).toUpperCase();
              if (s.length() == 1) s = "0" + s;
              System.out.print(s + " ");
            } // for
            System.out.println("");
            // set APDU buffer size
            CommandAPDU command = new CommandAPDU(MAX_APDU_SIZE); // create APDU buffer and set size
            //----- prepare command APDU - SELECT APPLET
            command.append(CMD_SELECT_APPLET);
            // send command and receive response
            ResponseAPDU response = ptcs.sendCommandAPDU(command);
            // show command apdu
            System.out.print("Command-APDU:  ");
            for (n = 0; n<command.getLength(); n++) {
              s = Integer.toHexString(command.getByte(n)).toUpperCase();
              if (s.length() == 1) s = "0" + s;
              System.out.print(s + " ");
            } // for
            System.out.println("");
            // show response apdu
            System.out.print("Response-APDU: ");
            for (n = 0; n < response.getLength(); n++) {
              s = Integer.toHexString(response.getByte(n)).toUpperCase();
              if (s.length() == 1) s = "0" + s;
              System.out.print(s + " ");
            } // for
            System.out.println("");
            //----- prepare command APDU - SET STRING
            command.setLength(0);
            command.append(CMD_SET_STRING);
            // send command and receive response
            response = ptcs.sendCommandAPDU(command);
            // show command apdu
            System.out.print("Command-APDU:  ");
            for (n = 0; n < command.getLength(); n++) {
              s = Integer.toHexString(command.getByte(n)).toUpperCase();
              if (s.length() == 1) s = "0" + s;
              System.out.print(s + " ");
            } // for
            System.out.println("");
            // show int response apdu
            System.out.print("Response-APDU: ");
            for (n=0; n<response.getLength(); n++) {
              s = Integer.toHexString(response.getByte(n)).toUpperCase();
              if (s.length() == 1) s = "0" + s;
              System.out.print(s + " ");
            } // for
            System.out.println("");
            //----- prepare command APDU - READ STRING
            command.setLength(0);
            command.append(CMD_READ_STRING);
            // send command and receive response
            response = ptcs.sendCommandAPDU(command);
            // show command apdu
            System.out.print("Command-APDU:  ");
            for (n = 0; n < command.getLength(); n++) {
              s = Integer.toHexString(command.getByte(n)).toUpperCase();
              if (s.length() == 1) s = "0" + s;
              System.out.print(s + " ");
            } // for
            System.out.println("");
            // show response apdu
            System.out.print("Response-APDU: ");
            for (n = 0; n < response.getLength(); n++) {
              s = Integer.toHexString(response.getByte(n)).toUpperCase();
              if (s.length() == 1) s = "0" + s;
              System.out.print(s + " ");
            } // for
            System.out.println("\ndeactivate Smart Card");
            SmartCard.shutdown();
          } // if
          else System.out.println("could not create smart card object (e.g. no ICC in IFD)");
        } // try
        catch (Exception e) {
         System.err.println("Caught exception '" + e.getClass() + "' - " + e.getMessage() );
        } // catch
        finally {
          System.exit(0);
        } // finally
      } // run example
      public static void main( String [] args ){
        System.out.println("---------------\nStart ST Terminal Test\n");
        STTerminalTest TerminalTest = new STTerminalTest();
        TerminalTest.runExample();
      } // main
    } // classWhen I run program, it promt that
    activate Smart Card
    Uses ISOTPDU
    wait for smart card - insert smart card in terminal
    Card ATR:           3B DF 18 00 00 80 5A 45 4C 4D 2D 57 4C 33 34 4D 31 82 90 00
    Caught exception 'class opencard.core.terminal.CardTerminalException' - Pcsc10CardTerminal: PCSC Exception in method SCardTransmit: error occurred with SCardTransmit
    return code = 8010002fSo, What am I wrong.
    PS: I am using Omikey CardMan 3x21 and ST Open JC card.
    I think my applet is not installed on card because when I installed the applet, it done successfull, But when I removed the card from reader and sent commands with JCOP tool, it promt that: Cannot select Card Manager. So What should I do now?
    Thanks!
    Edited by: lovemyself on Aug 6, 2008 1:40 AM

    Dmitri,
    Thanh you very much.
    Now I want to install my applet by using JCOP and Omnikey CardMan 3x21.I can not select the CardManager.
    /term "winscard:4|OMNIKEY CardMan 3x21 0"
    --Opening terminal
    /card -a a000000003000000 -c com.ibm.jc.CardManager--Waiting for card...
    ATR=3B DF 18 00 00 80 5A 45 4C 4D 2D 57 4C 33 34 4D    ;.....ZELM-WL34M
        31 82 90 00                                        1...
    ATR: T=0, FI=1/DI=8 (31clk/etu), N=0, Hist=805A454C4D2D574C33344D31829000
    => 00 A4 04 00 08 A0 00 00 00 03 00 00 00 00          ..............
    jcshell: Unable to select Card Manager or invalid FCI: Unknown Global Platform Java Card.
    Subsequent commands might fail! Inspection might not be possible!
    ??>  set-key 255/1/DES-ECB/404142434445464748494a4b4c4d4e4f 255/2/DES-ECB/404142434445464748494a4b4c4d4e4f 255/3/DES-ECB/404142434445464748494a4b4c4d4e4f
    ??>  init-update 255
    => 80 50 00 00 08 21 F6 00 11 AB CF 28 02 00          .P...!.....(..
    (26251 usec)
    <= 6E 00                                              n.
    Status: CLA value not supported
    jcshell: Error code: 6e00 (CLA value not supported)
    jcshell: Wrong response APDU: 6E00
    Unexpected error; aborting executionShow, how I can config the reader to install applet?
    Edited by: lovemyself on Aug 7, 2008 8:31 PM

  • Problem with select APDU

    Hi all
    I have a problem when trying to test an applet created by me like Sebastian Lorquet proposed in this post:
    Re: Ask Global Platform SecureChannel
    I managed to install my applet on the card, and when I check the applets it contains I can see that the AID of mine appears.
    But when I use it and send APDUs through it, the SELECT command fails me.
    The SELECT APDU instruction is:
    Command -> 00A404000B0102030405060708090000
    where 01 02 03 04 05 06 07 08 09 00 00 is the AID of my applet
    The response is as follows:
    Response <- 6D00 (Invalid instruction byte / Command not supported or invalid)
    Do not understand why I get that answer.
    I am using gpshell, and the command used is:
    select -AID 0102030405060708090000
    Thanks in advance
    Edited by: bra_racing on 05-jul-2012 15:28

    ah ok. Just answer me one thing, are you using below code ?
    package test;
    import javacard.framework.APDU;
    import javacard.framework.Applet;
    import javacard.framework.ISO7816;
    import javacard.framework.ISOException;
    import org.globalplatform.GPSystem;
    import org.globalplatform.SecureChannel;
    * @author shane
    public class TestSecureChannel extends Applet {
        private final static byte INS_INIT_UPDATE = 0x50;
        private final static byte INS_EXT_AUTH = (byte) 0x82;
        private TestSecureChannel() {
            // empty
        public static void install(byte bArray[], short bOffset, byte bLength) throws ISOException {
            new TestSecureChannel().register();
        public void process(APDU apdu) throws ISOException {
            if (selectingApplet()) {
                return;
            byte[] buffer = apdu.getBuffer();
            byte cla = buffer[ISO7816.OFFSET_CLA];
            byte ins = buffer[ISO7816.OFFSET_INS];
            SecureChannel sc = GPSystem.getSecureChannel();
            if ((byte) (cla & 0x80) == 0x80) {
                switch (ins) {
                    case INS_INIT_UPDATE:
                    case INS_EXT_AUTH:
                        apdu.setOutgoingAndSend(ISO7816.OFFSET_CDATA, sc.processSecurity(apdu));
                        return;
                    default:
                        // fall through
            switch (ins) {
                case (byte) 0x01:
                    buffer[0] = sc.getSecurityLevel();
                    apdu.setOutgoingAndSend((short) 0, (short) 1);
                    break;
                default:
                    ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
    }If not above one then copy past your code here. For time being for what I understand it that to send get data command your currently selected application should be card manager.
    Edited by: Umer on Jul 10, 2012 4:34 PM

  • Detect SELECT APDU

    Hi everyone
    I'm writing an applet (Java Card 2.1.1) and in the process method I'm trying to detect the SELECT APDU command, but it's not working. I send a SELECT APDU to my applet, it throws a SW_CLA_NOT_SUPPORTED exception, and it is selected. Ok, the command ends up doing what it is supposed to do, but my applet throws an exception, and it shouldn't.
    Here's my code:
    public void process(APDU apdu) throws ISOException {
      byte[] buffer = apdu.getBuffer();
      byte cla  = buffer[ISO7816.OFFSET_CLA];
      byte ins = buffer[ISO7816.OFFSET_INS];
      if (cla == CLA_FUNCIONARIO) {
          try {
              switch (ins) {
                  // all my cases
                  default:
                      ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
          catch (UserException e) {
              ISOException.throwIt(e.getReason());
      else if (selectingApplet()) {
          return;
      else {
          byte tamanho_lido = (byte) apdu.setIncomingAndReceive();
          apdu.setOutgoing();
          apdu.setOutgoingLength((short) (tamanho_lido + 4));
          apdu.sendBytes((short) 0, (short) 4);
          apdu.sendBytes(ISO7816.OFFSET_CDATA, tamanho_lido);
          ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
    }First of all, I don't know what exactly does the method selectingApplet - in several source codes I've seen around, the verification for the SELECT APDU is done like this:
    (cla == ISO7816.CLA_ISO7816 && ins == ISO7816.INS_SELECT)But, there are some sample codes (like the JavaPurse on JCDK 2.1.1) that prove these two ways of checking the SELECT APDU is not equivalent. So, what's the difference between using the selectingApplet method and using the constants on the ISO7816 interface? Should I use both ways? Only one of them???
    The big problem is what is actually happening to my card. As it can be seen in the code above, if the applet is about to throw an SW_CLA_NOT_SUPPORTED exception, it writes the whole command that it received, so I can see what got there (sort of a System.out.println debugging). And here's what happens: everytime I send the command 0x00 0xA4 0x04 0x00 0x06 0x01 0x02 0x03 0x04 0x05 0x06 0x00, it returns 0x00 0xC0 0x00 0x00 as the response data and 0x6E00 as the status word!!! I googled and I found that C0 is the INS byte of the GET RESPONSE command. What is this command? It's not documented on the GlobalPlatform 2.0.1' specification. And why the hell my applet says it received this command when I send it a SELECT APDU?
    Any answer would be valuable :)
    Thanks!

    You are in the ISO7816 T=0 protocol. The 00CO000000 command is issued to receive the response to the previous SELECT command. You are not returning any data to the SELECT command, but the terminal side seems to insist on getting one.
    The GetResponse command should not be passed to the Applet by your card operating system, I consider this a bug.
    If you return data when selectingApplet() returns true, then you probably will not have any problem.

  • Exchanging APDU's with selected applet fails

    Hi all,
    1. I developed a cardlet( normal, sample one) using JCOP
    2. Installed, selected and excanged APDU's with this applet ( on Nokia 6212,6131 and JCOP cards)
    3. Now i tried it on a SE of SIM. In this case, installation and selection succeeds but exchanging APDU's with selected applet is partial. by 'partial' what i mean is:
    i am using 0x90 as CLA byte for personalisation (now i am not checking the CLA byte from cardelt code)
    private static final byte STORE=0x01;
    private static final byte GET=0x02; , and these are INS values for getting and storing personalisation data.
    if i send STORE command like */send 90010000084142434445464748* (8 data bytes ), only first 5 bytes are being transferred to applet (i tested this fact by returning the buffer(apdu.getBuffer()) length from process(APDU apdu) function ), not the actual data. ie, only CLA, INS, P1, P2, and LC fields are being transferred to applet. so, currently the actual personlisation data is not been transferred to selected applet.
    Is there any specific data format that has to be send to a selected applet ?
    or
    In which point i am going wrong ?
    This is the cardlet code i'm using
    import javacard.framework.APDU;
    import javacard.framework.ISO7816;
    import javacard.framework.Applet;
    import javacard.framework.ISOException;
    import javacard.framework.Util;
    public class TestCard extends Applet
        private static final byte STORE=0x01;
        private static final byte GET=0x02;
        private static byte personalized=0x00;
        private static byte[] value=null;
       // private static byte testByte;
        public static void install(byte[] bArray, short bOffset, byte bLength)
            // GP-compliant JavaCard applet registration
            new TestCard().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
        public void process(APDU apdu)
            // Good practice: Return 9000 on SELECT
            if (selectingApplet())
                return;
            byte[] buf = apdu.getBuffer();
            switch (buf[ISO7816.OFFSET_INS])
                case STORE:
                    value=new byte[buf[ISO7816.OFFSET_LC]];
                    //testByte=(byte)buf.length;
                    Util.arrayCopy(buf, (short)(ISO7816.OFFSET_LC+1), value, (short)0, buf[ISO7816.OFFSET_LC]);
                    personalized=(byte)0x01;
                    break;
                case GET:
                    if(personalized==0x00)
                        ISOException.throwIt((short)0x6999);
                        break;
                    //value=new byte[]{testByte};
                    apdu.setOutgoing();
                    apdu.setOutgoingLength((short)value.length);
                    apdu.sendBytesLong(value, (short)0, (short)value.length);
                    break;
                default:
                    // good practice: If you don't know the INStruction, say so:
                    ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
    }and this is the JCOP script i'm using
    /echo Opening terminal
    /terminal "winscard:4|OMNIKEY CardMan 5x21-CL 0"
    /echo Resets card
    /atr
    /echo Selecting TestCard Applet
    /select 11223344556600
    /echo Sending 8-byte Personalisation data ABCDEFGH (4142434445464748)
    /send 90010000084142434445464748
    /echo Reading personalised data
    /send 90020000and the output trace is
    /echo Opening terminal
    Opening terminal
    /terminal "winscard:4|OMNIKEY CardMan 5x21-CL 0"
    --Opening terminal
    /echo Resets card
    Resets card
    /atr
    --Waiting for card...
    ATR=3B 88 80 01 01 02 03 04 00 81 C0 00 4C             ;...........L
    /echo Selecting TestCard Applet
    Selecting TestCard Applet
    /select 11223344556600
    => 00 A4 04 00 07 11 22 33 44 55 66 00 00             ......"3DUf..
    (84234 usec)
    <= 90 00                                              ..
    Status: No Error
    /echo Sending 8-byte Personalisation data ABCDEFGH (4142434445464748)
    Sending 8-byte Personalisation data ABCDEFGH (4142434445464748)
    /send 90010000084142434445464748
    => 90 01 00 00 08 41 42 43 44 45 46 47 48             .....ABCDEFGH
    (168449 usec)
    <= 90 00                                              ..
    Status: No Error
    /echo Reading personalised data
    Reading personalised data
    /send 90020000
    => 90 02 00 00                                        ....
    (22838 usec)
    <= 00 00 00 00 00 00 00 00 90 00                      ."3DUf.... // here not getting the actual needed data.
    Status: No ErrorThanks and regards
    Sunil

    Hi all,
    after lot of trial and error and research, i found that in the above code, i am not using
    apdu.setIncomingAndReceive();this is where the problem lies. i set incoming mode after reading the apdu buffer and the problem solved.
    thanks and regards
    sunil

  • Send select apdu with jcoop

    Hi, finally i have been able to install the applet in my nokia 6131 NFC!
    now i want to send a select apdu command.
    the card-info says that my applet is loaded.
    Card Manager AID   :  A000000003000000
    Card Manager state :  SECURED
        Application:  SELECTABLE (---L----) D276000005AB0503E0040101
        Application:  SELECTABLE (--------) D276000005AA0503E0050101
        Application:  SELECTABLE (--------) A00000006203010C01
        Load File  :      LOADED (--------) A0000000035350   (Security Domain)
        Load File  :      LOADED (--------) D276000005AA040360010410
        Load File  :      LOADED (--------) D276000005AA0503E00401
        Load File  :      LOADED (--------) D276000005AA0503E00501
        *Load File  :      LOADED (--------) 0A0000006203010C0101*I have tried the following commands:
    May be the state of the applet would be "SELECTABLE"? How can i change this state?
    cm>  /select 0A0000006203010C0101
    => 00 A4 04 00 0A 0A 00 00 00 62 03 01 0C 01 01 00    .........b......
    (11395 usec)
    <= 6A 82                                              j.
    Status: File not found
    jcshell: Error code: 6a82 (File not found)
    jcshell: Wrong response APDU: 6A82
    cm>  send 00a404000a0A0000006203010C0101
    => 00 A4 04 00 0A 0A 00 00 00 62 03 01 0C 01 01       .........b.....
    (11300 usec)
    <= 6A 82                                              j.
    Status: File not found

    You have a typo in your SELECT command. According to GET STATUS the AID of the targeted application is
    AID: A0 00 00 00 62 03 01 0C 01
    and you're sending in the select command
    CLA, INS, P1, P2, Lc: 00 A4 04 00 0A
    AID 0A 00 00 00 62 03 01 0C 01 01
    See the difference? Furthermore you cannot select packages, only applications which are in the SELECTABLE application life cycle.

  • SELECT APDU? How do I interprete this SW1 and SW2? HELP!

    Hi,
    Earlier today I had problems regarding communicating with my GemPlus PC430. I used OpenCard Framework. I've now discovered that Java 6 has support for smartcards through javax.smartcardio.*. I can now communicate with the cardreader/card, but when I do so I get the output shown be. How should I interpret the values of Select Resp and response.
    Terminals: [PC/SC terminal Gemplus GemPC430 0]
    card: PC/SC card in Gemplus GemPC430 0, protocol T=0, state OK
    Select Resp:  6A 82
    response:  6D 00
    I use the following APDU's:
    static byte[] selectUserApplet = new byte[] {(byte)0x00, (byte)0xA4, (byte)0x04, (byte)0x00, (byte)0x09, (byte)0xa0, (byte)0x0, (byte)0x0, (byte)0x0, (byte)0x62, (byte)0x3, (byte)0x1, (byte)0xc, (byte)0x5};
    static byte[] getID = {(byte)0x80, (byte)0x02, (byte)0x00, (byte)0x00};
    The AID is: 0xa0:0x0:0x0:0x0:0x62:0x3:0x1:0xc:0x5
    The CLA is: 0x80
    The INS is: 0x02
    So - what is the 6A 82 and the 6D 00?
    Thank you in advance...
    Kind Regards
    /Haber
    Edited by: Haber on Sep 20, 2007 9:41 AM

    When I load the Applet this is the out put is the applet loaded or?????????????
    Java Card 2.2.2 APDU Tool, Version 1.3
    Copyright 2005 Sun Microsystems, Inc. All rights reserved. Use is subject to lic
    ense terms.
    WARNING: PC/SC is not officially supported and may not work on all platforms.
    Before SCardEstablishContext ...
    After SCardEstablishContext ...
    SUCCESS ...-855572480
    Reader 0 : Gemplus GemPC430 0NativeConnect Context is ... -855572480
    NativeConnect card is ... ea010000
    NativeStatus card is ... ea010000
    Received ATR = 0x3f 0x6d 0x00 0x00 0x80 0x31 0x80 0x65 0xb0 0x05 0x01 0x02 0x5e 0x83 0x00 0x90 0x00
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 14
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 00, INS: a4, P1: 04, P2: 00, Lc: 09, a0, 00, 00, 00, 62, 03, 01, 08, 01, Le: 00, SW1: 6a, SW2: 82
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 5
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b0, P1: 00, P2: 00, Lc: 00, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 5
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b2, P1: 01, P2: 00, Lc: 00, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 27
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b4, P1: 01, P2: 00, Lc: 16, 01, 00, 13, de, ca, ff, ed, 01, 02, 04, 00, 01, 09, a0, 00, 00, 00, 62, 03, 01, 0c, 05, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 5
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: bc, P1: 01, P2: 00, Lc: 00, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 5
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b2, P1: 02, P2: 00, Lc: 00, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 37
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b4, P1: 02, P2: 00, Lc: 20, 02, 00, 1f, 00, 13, 00, 1f, 00, 0e, 00, 15, 00, 7e, 00, 1e, 02, 18, 00, 12, 00, 4d, 00, 00, 01, 3d, 00, 03, 00, 01, 00, 04, 02, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 7
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b4, P1: 02, P2: 00, Lc: 02, 01, 00, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 5
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: bc, P1: 02, P2: 00, Lc: 00, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 5
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b2, P1: 04, P2: 00, Lc: 00, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 29
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b4, P1: 04, P2: 00, Lc: 18, 04, 00, 15, 02, 03, 01, 07, a0, 00, 00, 00, 62, 01, 01, 00, 01, 07, a0, 00, 00, 00, 62, 00, 01, Le: 00, SW1: 69, SW2:85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 5
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: bc, P1: 04, P2: 00, Lc: 00, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 5
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b2, P1: 03, P2: 00, Lc: 00, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 22
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b4, P1: 03, P2: 00, Lc: 11, 03, 00, 0e, 01, 0a, a0, 00, 00, 00, 62, 03, 01, 0c, 05, 01, 00, 0c, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 5
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: bc, P1: 03, P2: 00, Lc: 00, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 5
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b2, P1: 06, P2: 00, Lc: 00, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 37
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b4, P1: 06, P2: 00, Lc: 20, 06, 00, 1e, 00, 80, 03, 00, ff, 00, 07, 01, 00, 00, 00, 18, 00, 80, 03, 02, 00, 01, 04, 04, 00, 00, 00, b0, ff, ff, 00, a3, 00, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 6
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b4, P1: 06, P2: 00, Lc: 01, b8, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 5
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: bc, P1: 06, P2: 00, Lc: 00, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 5
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b2, P1: 07, P2: 00, Lc: 00, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 37
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b4, P1: 07, P2: 00, Lc: 20, 07, 02, 18, 00, 01, 40, 18, 8c, 00, 10, 18, 8b, 00, 1d, 7a, 04, 30, 8f, 00, 02, 18, 1d, 1e, 8c, 00, 03, 7a, 02, 21, 19, 8b, 00, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 37
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b4, P1: 07, P2: 00, Lc: 20, 04, 2d, 1a, 04, 25, 73, 00, 17, 00, 02, 00, 03, 00, 0b, 00, 11, 18, 19, 8c, 00, 05, 7a, 18, 19, 8c, 00, 06, 7a, 7a, 04, 22, 19, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 37
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b4, P1: 07, P2: 00, Lc: 20, 8b, 00, 04, 2d, 19, 8b, 00, 07, 32, 19, 7b, 00, 08, 92, 8b, 00, 09, 19, 7b, 00, 08, 03, 7b, 00, 08, 92, 8b, 00, 0a, 7a, 03, 22, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 37
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b4, P1: 07, P2: 00, Lc: 20, 19, 8b, 00, 04, 2d, 19, 8b, 00, 07, 32, 1a, 03, 7c, 00, 0b, 8d, 00, 0c, 3b, 19, 03, 04, 8b, 00, 0d, 7a, 05, 40, 18, 8c, 00, 10, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 37
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b4, P1: 07, P2: 00, Lc: 20, 18, 8f, 00, 0e, 3d, 06, 10, 08, 8c, 00, 0f, 87, 00, ad, 00, 19, 1e, 1f, 8b, 00, 11, 18, 8b, 00, 1d, 7a, 04, 30, 8f, 00, 12, 18, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 37
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b4, P1: 07, P2: 00, Lc: 20, 1d, 1e, 8c, 00, 13, 7a, 01, 10, ad, 00, 8b, 00, 14, 61, 04, 03, 78, 04, 78, 01, 10, ad, 00, 8b, 00, 15, 7a, 02, 21, 19, 8b, 00, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 37
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b4, P1: 07, P2: 00, Lc: 20, 04, 2d, 1a, 03, 25, 61, 0a, 1a, 04, 25, 10, a4, 6b, 03, 7a, 1a, 03, 25, 10, b0, 6a, 08, 11, 6e, 00, 8d, 00, 16, 1a, 04, 25, 75, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 37
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b4, P1: 07, P2: 00, Lc: 20, 00, 2d, 00, 04, 00, 20, 00, 27, 00, 30, 00, 21, 00, 40, 00, 1b, 00, 50, 00, 15, 18, 19, 8c, 00, 17, 7a, 18, 19, 8c, 00, 18, 7a, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 37
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b4, P1: 07, P2: 00, Lc: 20, 18, 19, 8c, 00, 19, 7a, 18, 19, 8c, 00, 1a, 7a, 11, 6d, 00, 8d, 00, 16, 7a, 03, 24, ad, 00, 8b, 00, 1b, 61, 08, 11, 63, 01, 8d, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 37
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b4, P1: 07, P2: 00, Lc: 20, 00, 16, 19, 8b, 00, 04, 2d, 1a, 07, 25, 32, 19, 8b, 00, 1c, 5b, 29, 04, 1f, 04, 6b, 07, 16, 04, 04, 6a, 08, 11, 67, 00, 8d, 00, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 37
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b4, P1: 07, P2: 00, Lc: 20, 16, 1a, 08, 25, 29, 05, 16, 05, 10, 7f, 6e, 06, 16, 05, 63, 08, 11, 6a, 83, 8d, 00, 16, af, 01, 16, 05, 41, 11, 7f, ff
    , 6f, 08, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 37
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b4, P1: 07, P2: 00, Lc: 20, 11, 6a, 84, 8d, 00, 16, 18, af, 01, 16
    , 05, 41, 89, 01, 7a, 03, 24, ad, 00, 8b, 00, 1b, 61, 08, 11, 63, 01, 8d, 00, 16
    , 19, 8b, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 37
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b4, P1: 07, P2: 00, Lc: 20, 00, 04, 2d, 1a, 07, 25, 32, 19, 8b, 00
    , 1c, 5b, 29, 04, 1f, 04, 6b, 07, 16, 04, 04, 6a, 08, 11, 67, 00, 8d, 00, 16, 1a
    , 08, 25, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 37
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b4, P1: 07, P2: 00, Lc: 20, 29, 05, 16, 05, 10, 7f, 6e, 06, 16, 05
    , 63, 08, 11, 6a, 83, 8d, 00, 16, af, 01, 16, 05, 43, 63, 08, 11, 6a, 85, 8d, 00
    , 16, 18, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 37
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b4, P1: 07, P2: 00, Lc: 20, af, 01, 16, 05, 43, 89, 01, 7a, 04, 22
    , 19, 8b, 00, 04, 2d, 19, 8b, 00, 07, 32, 1f, 05, 6d, 08, 11, 67, 00, 8d, 00, 16
    , 19, 05, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 37
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b4, P1: 07, P2: 00, Lc: 20, 8b, 00, 09, 1a, 03, af, 01, 10, 08, 4f
    , 5b, 38, 1a, 04, af, 01, 11, 00, ff, 53, 5b, 38, 19, 03, 05, 8b, 00, 0d, 7a, 04
    , 22, 19, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 32
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b4, P1: 07, P2: 00, Lc: 1b, 8b, 00, 04, 2d, 19, 8b, 00, 1c, 5b, 32
    , ad, 00, 1a, 08, 1f, 8b, 00, 1e, 61, 08, 11, 63, 00, 8d, 00, 16, 7a, Le: 00, SW
    1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 5
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: bc, P1: 07, P2: 00, Lc: 00, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 5
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b2, P1: 08, P2: 00, Lc: 00, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 26
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b4, P1: 08, P2: 00, Lc: 15, 08, 00, 12, 00, 03, 00, 01, 00, 01, 03
    , 00, 04, 4d, 61, 64, 73, 00, 00, 00, 01, 01, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 5
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: bc, P1: 08, P2: 00, Lc: 00, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 5
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b2, P1: 05, P2: 00, Lc: 00, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 37
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b4, P1: 05, P2: 00, Lc: 20, 05, 00, 7e, 00, 1f, 02, 00, 0c, 00, 02
    , 00, 0c, 01, 01, 00, 00, 00, 06, 00, 00, 01, 03, 80, 0a, 01, 06, 00, 00, 3a, 06
    , 00, 00, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 37
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b4, P1: 05, P2: 00, Lc: 20, 5b, 03, 80, 0a, 07, 05, 00, 00, 00, 03
    , 80, 0a, 09, 03, 80, 0a, 05, 05, 00, 00, 02, 06, 80, 10, 06, 03, 80, 0a, 04, 01
    , 80, 09, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 37
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b4, P1: 05, P2: 00, Lc: 20, 00, 06, 80, 09, 00, 06, 80, 03, 00, 03
    , 80, 09, 08, 01, 00, 0c, 00, 06, 00, 00, 77, 03, 80, 09, 02, 03, 80, 09, 05, 06
    , 80, 07, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 37
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b4, P1: 05, P2: 00, Lc: 20, 01, 06, 00, 01, c5, 06, 00, 01, 6c, 06
    , 00, 01, 10, 06, 00, 01, fa, 03, 80, 09, 04, 03, 80, 0a, 06, 03, 80, 03, 01, 03
    , 80, 09, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 6
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b4, P1: 05, P2: 00, Lc: 01, 01, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 5
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: bc, P1: 05, P2: 00, Lc: 00, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 5
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b2, P1: 09, P2: 00, Lc: 00, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 37
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b4, P1: 09, P2: 00, Lc: 20, 09, 00, 4d, 00, 0f, 89, 02, 1b, 0d, 60
    , 41, 11, 05, 05, 41, 0e, 05, 20, 09, 1c, 00, 3a, 05, 04, 06, 06, 07, 14, 06, 08
    , 05, 05, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 37
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b4, P1: 09, P2: 00, Lc: 20, 04, 04, 04, 04, 07, 05, 06, 03, 07, 07
    , 04, 07, 0a, 04, 06, 06, 08, 0d, 07, 1b, 1d, 06, 06, 06, 07, 08, 08, 04, 09, 12
    , 15, 10, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 21
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b4, P1: 09, P2: 00, Lc: 10, 10, 08, 04, 09, 12, 15, 0d, 0f, 05, 0b
    , 05, 19, 07, 05, 0a, 08, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 5
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: bc, P1: 09, P2: 00, Lc: 00, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 5
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: ba, P1: 00, P2: 00, Lc: 00, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 17
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 80, INS: b8, P1: 00, P2: 00, Lc: 0c, 0a, a0, 00, 00, 00, 62, 03, 01, 0c, 05
    , 01, 00, Le: 00, SW1: 69, SW2: 85
    NativeTransmit card is ... ea010000
    NativeTransmit_barray(): inlen 15
    NativeTransmit_barray(): return code 0x0, return length 2
    CLA: 00, INS: a4, P1: 04, P2: 00, Lc: 0a, a0, 00, 00, 00, 62, 03, 01, 0c, 05, 01
    , Le: 00, SW1: 6a, SW2: 82
    NativeDisconnect is ... ea010000

  • SELECT APDU

    Hello all!
    I can't select my applet in the JCWDE.
    I have a myapp.app file that contains:
    com.sun.javacard.installer.InstallerApplet 0xa0:0x0:0x0:0x0:0x62:0x3:0x1:0x8:0x1
    com.myapplet.javacard.MyClass               0xa0:0x0:0x0:0x0:0x62:0x3:0x1:0xc:0x6:0x1
    the applet AID matches with the AID definition in the opt file that used in convertion.
    I run the jcwde and the apdutool to sent the script APDU. The scr file contains:
    powerup;
    // select MyClass
    0x00 0xA4 0x04 0x00 10 0xa0 0x0 0x0 0x0 0x62 0x3 0x1 0xc 0x6 0x1 0xFF;
    powerdown;
    but the result of the status word (SW1) is 6d :-/ the correct value is 90 (sucessfull)
    the result of the apdutool command is:
    Java Card 2.2 ApduTool (version 0.20)
    Copyright 2002 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.
    Opening connection to localhost on port 9025.
    Connected.
    Received ATR = 0x3b 0xf0 0x11 0x00 0xff 0x00
    CLA: 00, INS: a4, P1: 04, P2: 00, Lc: 0a, a0, 00, 00, 00, 62, 03, 01, 0c, 06, 01, Le: 00, SW1: 6d, SW2: 00
    Anybody can help me?!
    Where is the problem?
    rgds,
    Igor Medeiros
    ICQ 39815017

    No :-/
    Now, my app file contains:
    powerup;
    // select the applet installer
    0x00 0xA4 0x04 0x00 0x09 0xa0 0x0 0x0 0x0 0x62 0x3 0x1 0x8 0x1 0x7F;
    // 90 00 = SW_NO_ERROR
    // create a instance of my applet
    0x80 0xB8 0x00 0x00 10 0xa0 0x0 0x0 0x0 0x62 0x3 0x1 0xc 0x6 0x1 0x7F;
    // select my applet
    0x00 0xA4 0x04 0x00 10 0xa0 0x0 0x0 0x0 0x62 0x3 0x1 0xc 0x6 0x1 0x7F;
    powerdown;
    but the result is
    CLA: 00, INS: a4, P1: 04, P2: 00, Lc: 09, a0, 00, 00, 00, 62, 03, 01, 08, 01, Le: 00, SW1: 90, SW2: 00
    CLA: 80, INS: b8, P1: 00, P2: 00, Lc: 0a, a0, 00, 00, 00, 62, 03, 01, 0c, 06, 01, Le: 00, SW1: 64, SW2: 43
    CLA: 00, INS: a4, P1: 04, P2: 00, Lc: 0a, a0, 00, 00, 00, 62, 03, 01, 0c, 06, 01, Le: 00, SW1: 6d, SW2: 00
    only the first command return a status word 90 :-/
    Can you help me?
    Thank you very much,
    Igor Medeiros

  • SELECT APDU disables STK events?

    Hi,
    How come after I select an applet with the SELECT APDU command, STK events no longer trigger the processToolkit method?
    STK events work fine prior to the APDU command. After an applet has been selected, not even the menu event works.
    Thanks all!

    Although you would have had your answers by now .... but if incase .... :)
    There is a difference between ToolkitApplets and normal Applets. When working with Toolkit Applet, the method processToolkit() is actually provoked by "GSM Applet" which is actually the selected Applet at the moment.
    Thanks,
    AQ

  • Wrong Instruction Class (6E 00) when with APDU for SELECT installer applet

    Hi
    I started up with developing SIM Application Toolkit Applets last week.
    I compiled and converted a sample applet, but I can't get to load it onto the SIM card.
    I am using a SIM reader/writer to issue the APDU commands in the script file that I had generated using the scriptgen command of the Java Card Development Kit, but I keep getting response 6E 00 (ie wrong instruction class) when I first issue the APDU that selects the Installer applet {00 A4 04 00 09 a0 00 00 00 62 03 01 08 01 (9000)}.
    I also tried using GPshell to install my applet to the SIM card, but I would also get Wrong Instruction Class when it tries to issue the APDU that does the installer applet selection.
    I don't know if I'm doing the right thing to load my applet to the SIM or if I'm completely off track, and if I am doing this right, I don't know why it isn't working.
    Thanks in advance.
    Best, Shadi AKIKI

    Shadi_Akiki wrote:
    Hi
    I started up with developing SIM Application Toolkit Applets last week.
    I compiled and converted a sample applet, but I can't get to load it onto the SIM card.
    I am using a SIM reader/writer to issue the APDU commands in the script file that I had generated using the scriptgen command of the Java Card Development Kit, but I keep getting response 6E 00 (ie wrong instruction class) when I first issue the APDU that selects the Installer applet {00 A4 04 00 09 a0 00 00 00 62 03 01 08 01 (9000)}.
    I also tried using GPshell to install my applet to the SIM card, but I would also get Wrong Instruction Class when it tries to issue the APDU that does the installer applet selection.
    I don't know if I'm doing the right thing to load my applet to the SIM or if I'm completely off track, and if I am doing this right, I don't know why it isn't working.
    Thanks in advance.
    Best, Shadi AKIKIcan someone please tell me what do does bytes mean: {00 A4 04 00 09 a0 00 00 00 62 03 01 08 01 (9000)}.
    I know cla, ins ter p1 in p2... but dont know how to set fid, size and so one when i am creating file... help

  • Is it possible send a SELECT APDU from one applet to another?

    Hello i want to select one applet from another. is it possible and how?. Thanks

    OK, I went to use this today, and can't figure it out.  Where do I place this code; In the SQL of a query, In the VBA of a form, or In a Modual?
    UPDATE Registrations RIGHT JOIN Registrations2
    ON Registrations.TEXT_REGISTRANT_ID = Registrations2.TEXT_REGISTRANT_ID
    SET Registrations.TEXT_REGISTRANT_ID = Registrations2.TEXT_REGISTRANT_ID,
    Registrations.[Name] = Registrations2.[Name]

  • Error while sending an APDU 6d 00

    Hello,
    I'm testing Javacard and i just want to send vie smartcard io an apdu command 0x80 0x07 0x00 0x00.
    As an response i should get: a simple string back.
    However, it doesen't work. After I selected more or less every ins byt eI'm sending results in an 6d00.
    But if I'm sending it via the APDUTOOL I'm getting the correct answer??
    Must have something to do with the transformation from in to byte. But I don't see where...
    Here is the java code:
    public class SCcommunication {
         private TerminalFactory factory;
         private List<CardTerminal> terminals;
         private CardTerminal terminal;
         private Card card;
         private CardChannel channel;
         private ResponseAPDU response;
         private boolean protocollType;
         private int sendLength;
         private int selectLength; //00 A4 04 00 + LE + aid
         private byte send[], select[];
         private CommandAPDU command;
         //generate a factory, get terminal list, and take the first terminal available (get(0))!
         public SCcommunication(){
              factory= TerminalFactory.getDefault();
              try{
                   terminals = factory.terminals().list();
              catch (CardException ec){
                   ec.printStackTrace();
              terminal = terminals.get(0);
              //if protocolltype=flase then protocoll is T0 else T1
              protocollType=false;
              selectLength=13;
              sendLength=133;
              select= new byte[selectLength];
              select[0]=(byte)(0x00);select[1]=(byte)(0xA4);select[2]=(byte)(0x04);select[3]=(byte)(0x0); select[4]=(byte)(8);
              select[5]=(byte)(0xAB); select[6]=(byte)(0xCD); select[7]=(byte)(0xEF); select[8]=(byte)(0xFE); select[9]=(byte)(0xDC); select[10]=(byte)(0x12);
              select[11]=(byte)(0x34); select[12]=(byte)(0x56); //select[13]=(byte)(0x01); select[14]=(byte)(0x01);
              send= new byte[sendLength];
         public void switchProtocoll(){
              if (!protocollType==true)
                   protocollType=false;
              else
                   protocollType=true;
         public void selectApplet(byte selectAPDU[]){
              try{
              if (protocollType)
                   card = terminal.connect("T=0");
              else
                   card = terminal.connect("T=1");
              channel= card.getBasicChannel();
              response=channel.transmit(new CommandAPDU(select));
              byte respByte[]=response.getBytes();
              System.out.print("The response: ");
              System.out.println();
              for (int i=0;i<respByte.length;i++){     
                   System.out.print(Integer.toHexString(respByte&0xff)+"||");
              System.out.println();
              // the card is not reseted after disconnect, due to false
              card.disconnect(false);
              catch (CardException ec){
                   ec.printStackTrace();
         public void sendToCard(){
              try{
                   if (protocollType)
                        card=terminal.connect("T=0");
                   else
                        card=terminal.connect("T=1");
                   channel= card.getBasicChannel();
                   //response=channel.transmit(new CommandAPDU(send));
                   send[0]=(byte)0x80; send[1]=(byte)0x07; send[2]=(byte)(0x00);send[3]=(byte)(0x00); send[4]=(byte)(128);
                   System.out.println("The response: ");
                   response=channel.transmit(new CommandAPDU(send));
                   byte respByte[]=response.getBytes();
                   for (int i=0;i<respByte.length;i++){
                        System.out.print(Integer.toHexString(respByte[i]&0xff)+"||");
                   System.out.println();
                   System.out.println("Done");
              // the card is not reseted after disconnect, due to false
                        card.disconnect(false);
              catch (CardException ec){
                   ec.printStackTrace();
         public static void main (String args[]){
              SCcommunication sc = new SCcommunication();
              sc.switchProtocoll();
              sc.selectApplet(sc.select);
              sc.sendToCard();
    Here is the corresponending Java Card code:
    public void process(APDU apdu) throws ISOException {
              // this is the text string which will send back from the ICC to the IFD
              final byte[] text = {(byte) 'H', (byte) 'l', (byte) 'l', (byte) ' ',
              (byte) 'o', (byte) 'M', (byte) 'n', (byte) 'a', (byte) 'm', (byte) ' ',
              (byte) 'e', (byte) 'i', (byte) 's', (byte) 'C',
              (byte) 'h', (byte) 'a', (byte) 'r', (byte) 'l', (byte) 'y'};
              // this is the install method which will be called once for installation
              // and registration of the applet
              // this is the method, which will be called from JCRE
              // the cmd_apdu variable is used because of performance reasons
              byte[] cmd_apdu = apdu.getBuffer();
              if (cmd_apdu[0] ==(byte)0x80) {  // it is the rigth class   
              short len_text = (short)text.length; // the len_text variable is used because of performance reasons
              apdu.setOutgoing(); // set transmission to outgoing data
              apdu.setOutgoingLength((short)len_text); // set the number of bytes to send to the IFD
              apdu.sendBytesLong(text, (short)0, (short)len_text);
              } // if
                   else{
                        ISOException.throwIt(ISO7816.SW_NO_ERROR);
              } // process
    Does anybode have any idea?
    Best regards

    Repost with code tgas:
    866393 wrote:
    Hello,
    I'm testing Javacard and i just want to send vie smartcard io an apdu command 0x80 0x07 0x00 0x00.
    As an response i should get: a simple string back.
    However, it doesen't work. After I selected more or less every ins byt eI'm sending results in an 6d00.
    But if I'm sending it via the APDUTOOL I'm getting the correct answer??
    Must have something to do with the transformation from in to byte. But I don't see where...
    Here is the java code:
    public class SCcommunication {
         private TerminalFactory factory;
         private List<CardTerminal> terminals;
         private CardTerminal terminal;
         private Card card;
         private CardChannel channel;
         private ResponseAPDU response;
         private boolean protocollType;
         private int sendLength;
         private int selectLength; //00 A4 04 00 + LE + aid
         private byte send[], select[];
         private CommandAPDU command;
         //generate a factory, get terminal list, and take the first terminal available (get(0))!
         public SCcommunication(){
              factory= TerminalFactory.getDefault();
              try{
                   terminals = factory.terminals().list();
              catch (CardException ec){
                   ec.printStackTrace();
              terminal = terminals.get(0);
              //if protocolltype=flase then protocoll is T0 else T1
              protocollType=false;
              selectLength=13;
              sendLength=133;
              select= new byte[selectLength];
              select[0]=(byte)(0x00);select[1]=(byte)(0xA4);select[2]=(byte)(0x04);select[3]=(byte)(0x0); select[4]=(byte)(8);
              select[5]=(byte)(0xAB); select[6]=(byte)(0xCD); select[7]=(byte)(0xEF); select[8]=(byte)(0xFE); select[9]=(byte)(0xDC); select[10]=(byte)(0x12);
              select[11]=(byte)(0x34); select[12]=(byte)(0x56); //select[13]=(byte)(0x01); select[14]=(byte)(0x01);
              send= new byte[sendLength];
         public void switchProtocoll(){
              if (!protocollType==true)
                   protocollType=false;
              else
                   protocollType=true;
         public void selectApplet(byte selectAPDU[]){
              try{
              if (protocollType)
                   card = terminal.connect("T=0");
              else
                   card = terminal.connect("T=1");
              channel= card.getBasicChannel();
              response=channel.transmit(new CommandAPDU(select));
              byte respByte[]=response.getBytes();
              System.out.print("The response: ");
              System.out.println();
              for (int i=0;i<respByte.length;i++){     
                   System.out.print(Integer.toHexString(respByte&0xff)+"||");
              System.out.println();
              // the card is not reseted after disconnect, due to false
              card.disconnect(false);
              catch (CardException ec){
                   ec.printStackTrace();
         public void sendToCard(){
              try{
                   if (protocollType)
                        card=terminal.connect("T=0");
                   else
                        card=terminal.connect("T=1");
                   channel= card.getBasicChannel();
                   //response=channel.transmit(new CommandAPDU(send));
                   send[0]=(byte)0x80; send[1]=(byte)0x07; send[2]=(byte)(0x00);send[3]=(byte)(0x00); send[4]=(byte)(128);
                   System.out.println("The response: ");
                   response=channel.transmit(new CommandAPDU(send));
                   byte respByte[]=response.getBytes();
                   for (int i=0;i<respByte.length;i++){
                        System.out.print(Integer.toHexString(respByte[i]&0xff)+"||");
                   System.out.println();
                   System.out.println("Done");
              // the card is not reseted after disconnect, due to false
                        card.disconnect(false);
              catch (CardException ec){
                   ec.printStackTrace();
         public static void main (String args[]){
              SCcommunication sc = new SCcommunication();
              sc.switchProtocoll();
              sc.selectApplet(sc.select);
              sc.sendToCard();
    Here is the corresponending Java Card code:
    public void process(APDU apdu) throws ISOException {
              // this is the text string which will send back from the ICC to the IFD
              final byte[] text = {(byte) 'H', (byte) 'l', (byte) 'l', (byte) ' ',
              (byte) 'o', (byte) 'M', (byte) 'n', (byte) 'a', (byte) 'm', (byte) ' ',
              (byte) 'e', (byte) 'i', (byte) 's', (byte) 'C',
              (byte) 'h', (byte) 'a', (byte) 'r', (byte) 'l', (byte) 'y'};
              // this is the install method which will be called once for installation
              // and registration of the applet
              // this is the method, which will be called from JCRE
              // the cmd_apdu variable is used because of performance reasons
              byte[] cmd_apdu = apdu.getBuffer();
              if (cmd_apdu[0] ==(byte)0x80) {  // it is the rigth class   
              short len_text = (short)text.length; // the len_text variable is used because of performance reasons
              apdu.setOutgoing(); // set transmission to outgoing data
              apdu.setOutgoingLength((short)len_text); // set the number of bytes to send to the IFD
              apdu.sendBytesLong(text, (short)0, (short)len_text);
              } // if
                   else{
                        ISOException.throwIt(ISO7816.SW_NO_ERROR);
              } // process
    Does anybode have any idea?
    Best regards

Maybe you are looking for