This discussion is archived
13 Replies Latest reply: Mar 1, 2012 11:43 PM by Umer RSS

Wrong data in installing applet using JCOP

919486 Newbie
Currently Being Moderated
Hi,

I am trying to develop a simple Java Card applet using JCOP Tools from NXP.
My applet would generate a RSA Key Pair and using the Public Key to encrypt some data.
However, when I tried simulating the applet, I got the following error in JCOP Shell:
install -i 456e6372797074  -q C9#() 656e6372797074 456e6372797074
 => 80 E6 0C 00 1E 07 65 6E 63 72 79 70 74 07 45 6E    ......encrypt.En
    63 72 79 70 74 07 45 6E 63 72 79 70 74 01 00 02    crypt.Encrypt...
    C9 00 00 00                                        ....
 (6391 usec)
 <= 6A 80                                              j.
Status: Wrong data
jcshell: Error code: 6a80 (Wrong data)
jcshell: Wrong response APDU: 6A80
Unexpected error; aborting execution
The package AID is 656e6372797074 and the applet AID is 456e6372797074.
Please help as this is kind of my first time with Java Card.

I post the whole JCOP Shell commands and responses here for easier debug:
cm>  /term "Remote|localhost:2578"
--Opening terminal
/card -a a000000003000000 -c com.ibm.jc.CardManager
resetCard with timeout: 0 (ms) --Waiting for card... ATR=3B F8 13 00 00 81 31 FE 45 4A 43 4F 50 76 32 34    ;.....1.EJCOPv24     31 B7                                              1. IOCTL(). ATR:          T = 1                   => 00 A4 04 00 08 A0 00 00 00 03 00 00 00 00          .............. (1240 usec) <= 6F 65 84 08 A0 00 00 00 03 00 00 00 A5 59 9F 65    oe...........Y.e     01 FF 9F 6E 06 47 91 01 17 33 00 73 4A 06 07 2A    ...n.G...3.sJ..*     86 48 86 FC 6B 01 60 0C 06 0A 2A 86 48 86 FC 6B    .H..k.`...*.H..k     02 02 01 01 63 09 06 07 2A 86 48 86 FC 6B 03 64    ....c...*.H..k.d     0B 06 09 2A 86 48 86 FC 6B 04 02 15 65 0B 06 09    ...*.H..k...e...     2B 85 10 86 48 64 02 01 03 66 0C 06 0A 2B 06 01    +...Hd...f...+..     04 01 2A 02 6E 01 02 90 00                         ..*.n.... Status: No Error cm>  set-key 255/1/DES-ECB/404142434445464748494a4b4c4d4e4f 255/2/DES-ECB/404142434445464748494a4b4c4d4e4f 255/3/DES-ECB/404142434445464748494a4b4c4d4e4f cm>  init-update 255 => 80 50 00 00 08 2E A8 D6 3E 6C 89 75 FC 00          .P......>l.u.. (3224 usec) <= 00 00 DE 81 34 18 39 B7 09 70 FF 02 00 00 3D 02    ....4.9..p....=.     9C 31 C7 89 64 61 11 E5 0F 78 E0 CF 90 00          .1..da...x.... Status: No Error cm>  ext-auth plain => 84 82 00 00 10 72 B0 AA 92 96 47 EA 1A 24 C1 9E    .....r....G..$..     CA 72 BE E2 7D                                     .r..} (20146 usec) <= 90 00                                              .. Status: No Error cm>  delete -r 656e6372797074 => 80 E4 00 80 09 4F 07 65 6E 63 72 79 70 74 00       .....O.encrypt. (1740 usec) <= 6A 88                                              j. Status: Reference data not found jcshell: Error code: 6a88 (Reference data not found) jcshell: Wrong response APDU: 6A88 Ignoring expected error cm>  upload -c -d -b 250 "C:\Workfile\Eclipse Projects\Encryption\bin\encryption\javacard\encryption.cap" => 80 E6 02 00 14 07 65 6E 63 72 79 70 74 08 A0 00    ......encrypt...     00 00 03 00 00 00 00 00 00 00                      .......... (3068 usec) <= 00 90 00                                           ... Status: No Error Start loading Header.cap (35 byte) => 80 E8 00 00 23 C4 82 02 D5 01 00 1C DE CA FF ED    ....#...........     02 02 04 00 01 07 65 6E 63 72 79 70 74 0A 65 6E    ......encrypt.en     63 72 79 70 74 69 6F 6E 00                         cryption. (2691 usec) <= 00 90 00                                           ... Status: No Error Header.cap loaded (35 byte) Start loading Directory.cap (36 byte) => 80 E8 00 01 24 02 00 21 00 1C 00 21 00 0B 00 1F    ....$..!...!....     00 6A 00 0E 00 D1 00 0A 00 28 00 00 00 D5 00 00    .j.......(......     00 00 00 00 00 00 03 01 00 00                      .......... (2323 usec) <= 00 90 00                                           ... Status: No Error Directory.cap loaded (36 byte) Start loading Import.cap (34 byte) => 80 E8 00 02 22 04 00 1F 03 03 01 07 A0 00 00 00    ...."...........     62 01 01 03 01 07 A0 00 00 00 62 01 02 03 01 07    b.........b.....     A0 00 00 00 62 02 01 00                            ....b... (3627 usec) <= 00 90 00                                           ... Status: No Error Import.cap loaded (34 byte) Start loading Applet.cap (14 byte) => 80 E8 00 03 0E 03 00 0B 01 07 45 6E 63 72 79 70    ..........Encryp     74 00 5B 00                                        t.[. (1732 usec) <= 00 90 00                                           ... Status: No Error Applet.cap loaded (14 byte) Start loading Class.cap (17 byte) => 80 E8 00 04 11 06 00 0E 00 00 00 80 03 05 00 05    ................     07 01 00 00 00 98 00                               ....... (2473 usec) <= 00 90 00                                           ... Status: No Error Class.cap loaded (17 byte) Start loading Method.cap (212 byte) => 80 E8 00 05 D4 07 00 D1 01 00 4C 80 05 00 53 00    ..........L...S.     14 05 11 18 8C 00 0E 18 07 11 04 00 03 8D 00 08    ................     94 00 00 11 87 02 18 08 11 04 00 03 8D 00 08 94    ................     00 00 10 87 01 18 8F 00 06 3D AD 02 AD 01 8C 00    .........=......     05 87 03 18 10 0C 03 8D 00 16 87 04 18 03 05 8D    ................     00 0A 87 00 AD 03 8B 00 0F 70 09 2C 11 69 86 8D    .........p.,.i..     00 0C 7A 05 30 8F 00 0B 3D 8C 00 17 18 1D 04 41    ..z.0...=......A     18 1D 25 8B 00 12 7A 06 22 19 8B 00 15 2D 19 8B    ..%...z."....-..     00 0D 32 AD 04 1A 08 1F AD 00 03 8B 00 09 3B AD    ..2...........;.     00 03 1A 08 1F 8D 00 19 3B 19 08 1F 8B 00 07 7A    ........;......z     02 21 18 8B 00 18 60 03 7A 19 8B 00 15 2D 1A 03    .!....`.z....-..     25 10 A0 6A 08 11 6E 00 8D 00 0C 1A 04 25 73 00    %..j..n......%s.     14 FF 90 FF 92 00 0D 00 14 00 1A 18 19 8C 00 13    ................     70 08 11 6D 00 8D 00 0C 7A 00                      p..m....z. (2120 usec) <= 00 90 00                                           ... Status: No Error Method.cap loaded (212 byte) Start loading StaticField.cap (13 byte) => 80 E8 00 06 0D 08 00 0A 00 00 00 00 00 00 00 00    ................     00 00 00                                           ... (1784 usec) <= 00 90 00                                           ... Status: No Error StaticField.cap loaded (13 byte) Start loading ConstantPool.cap (109 byte) => 80 E8 00 07 6D 05 00 6A 00 1A 02 00 02 04 02 00    ....m..j........     02 01 02 00 02 00 02 00 02 02 02 00 02 03 06 81    ................     10 01 01 81 10 00 03 80 0A 08 06 81 0D 00 03 82    ................     01 01 06 80 08 0D 01 00 02 00 06 80 07 01 03 80    ................     0A 06 06 80 03 00 03 81 10 01 01 81 08 00 01 81    ................     09 00 03 80 03 02 06 00 00 6F 01 81 0C 00 03 80    .........o......     0A 01 06 82 01 00 06 00 00 09 03 80 03 03 06 80    ................     10 01 00                                           ... (13424 usec) <= 00 90 00                                           ... Status: No Error ConstantPool.cap loaded (109 byte) Start loading RefLocation.cap (43 byte) => 80 E8 00 08 2B 09 00 28 00 0B 1D 0F 07 02 05 09    ....+..(........     08 02 2F 05 07 00 19 07 06 09 04 0B 04 06 08 09    ../.............     08 07 09 06 04 0A 07 05 0C 0A 07 07 07 0E 15 08    ................     00                                                 . (7604 usec) <= 00 90 00                                           ... Status: No Error RefLocation.cap loaded (43 byte) Start loading Descriptor.cap (216 byte) => 80 E8 80 09 D8 0B 00 D5 01 00 01 00 02 00 00 05    ................     00 04 00 02 00 02 00 00 36 01 02 00 02 01 00 3A    ........6......:     02 02 00 02 02 00 3E 03 02 00 02 03 00 42 04 02    ......>......B..     00 02 04 00 46 00 81 00 09 00 48 00 50 00 01 00    ....F.....H.P...     00 01 09 00 5B 00 4A 00 12 00 00 00 00 FF 02 00    ....[.J.........     6F 00 4D 00 27 00 00 00 00 07 01 00 98 00 4D 00    o.M.'.........M.     37 00 00 00 00 00 1A 00 46 00 3A 00 36 00 3E 00    7.......F.:.6.>.     42 00 51 FF FF 00 58 00 5B 00 60 00 64 FF FF 00    B.Q...X.[.`.d...     67 00 69 00 48 00 48 FF FF FF FF 00 4A 00 4D FF    g.i.H.H.....J.M.     FF 00 6B 00 6D 00 48 00 72 00 74 05 68 10 90 05    ..k.m.H.r.t.h...     68 10 80 05 68 11 00 05 68 20 10 01 B0 01 10 04    h...h...h ......     B4 31 06 68 00 A1 0B 68 10 36 81 02 10 03 44 10    .1.h...h.6....D.     08 34 26 81 00 06 B4 4B 44 03 43 B0 02 41 01 40    .4&....KD.C..A.@     01 B0 07 32 68 20 10 01 20 06 B4 B4 44 00          ...2h .. ...D. (3271 usec) <= 00 90 00                                           ... Status: No Error Descriptor.cap loaded (216 byte) Load report:   729 bytes loaded in 0.0 seconds   effective code size on card:       + package AID       7       + applet AIDs       14       + classes           17       + methods           212       + statics           0       + exports           0      ------------------------------         overall           250  bytes cm>  install -i 456e6372797074  -q C9#() 656e6372797074 456e6372797074 => 80 E6 0C 00 1E 07 65 6E 63 72 79 70 74 07 45 6E    ......encrypt.En     63 72 79 70 74 07 45 6E 63 72 79 70 74 01 00 02    crypt.Encrypt...     C9 00 00 00                                        .... (6391 usec) <= 6A 80                                              j. Status: Wrong data jcshell: Error code: 6a80 (Wrong data) jcshell: Wrong response APDU: 6A80 Unexpected error; aborting execution
  • 1. Re: Wrong data in installing applet using JCOP
    Umer Journeyer
    Currently Being Moderated
    Can you share the code plz
  • 2. Re: Wrong data in installing applet using JCOP
    919486 Newbie
    Currently Being Moderated
    Sure, I can.
    Here it is:
    /**
     * 
     */
    package encryption;
    
    import javacard.framework.APDU;
    import javacard.framework.ISO7816;
    import javacard.framework.Applet;
    import javacard.framework.ISOException;
    import javacard.framework.JCSystem;
    import javacard.framework.Util;
    import javacard.security.*;
    import javacardx.crypto.Cipher;
    
    /**
     * @author Khanh Huynh
     * 
     */
    public class EncryptionApp extends Applet
    {
         public final static byte ENCRYPT_CLA = (byte) 0xA0;
    
         public final static byte ENCRYPT_DATA = (byte) 0x90;
         public final static byte DECRYPT_DATA = (byte) 0x92;
         public final static byte SEND_PBL_KEY = (byte) 0x94;
    
         private RSAPublicKey keyRSAPublic = (RSAPublicKey) KeyBuilder.buildKey(
                   KeyBuilder.TYPE_RSA_PUBLIC, KeyBuilder.LENGTH_RSA_1024, false);
         private RSAPrivateKey keyRSAPrivate = (RSAPrivateKey) KeyBuilder.buildKey(
                   KeyBuilder.TYPE_RSA_PRIVATE, KeyBuilder.LENGTH_RSA_1024, false);
    
         private KeyPair keyPairRSA = new KeyPair(keyRSAPublic, keyRSAPrivate);
         private Cipher cipher = Cipher.getInstance(Cipher.ALG_RSA_NOPAD, false);
    
         private byte[] ramArray = JCSystem.makeTransientByteArray((short) 0,
                   JCSystem.CLEAR_ON_DESELECT);
    
         public EncryptionApp()
         {
    
              keyPairRSA.genKeyPair();
    
         }
    
         public static void install(byte[] bArray, short bOffset, byte bLength)
         {
              // GP-compliant JavaCard applet registration
    //          try {
                   new encryption.EncryptionApp().register(bArray, (short) (bOffset + 1),
                                  bArray[bOffset]);
    //          } finally {new encryption.EncryptionApp().register();}
              // new encryption.EncryptionApp().register();
         }
    
         private void encryptData(APDU apdu)
         {
              byte[] apduBuf = apdu.getBuffer();
              short dataLength = apdu.setIncomingAndReceive();
    
              cipher.init(keyRSAPublic, Cipher.MODE_ENCRYPT);
              cipher.doFinal(apduBuf, ISO7816.OFFSET_CDATA, dataLength, ramArray,
                        (short) 0);
              Util.arrayCopyNonAtomic(ramArray, (short) 0, apduBuf, ISO7816.OFFSET_CDATA,
                        dataLength);
              apdu.setOutgoingAndSend(ISO7816.OFFSET_CDATA, dataLength);
         }
    
         public void process(APDU apdu)
         {
              // Good practice: Return 9000 on SELECT
              if (selectingApplet())
              {
                   return;
              }
    
              byte[] buf = apdu.getBuffer();
    
              if (buf[ISO7816.OFFSET_CLA] != ENCRYPT_CLA)
                   ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
    
              switch (buf[ISO7816.OFFSET_INS])
              {
              case ENCRYPT_DATA:
                   encryptData(apdu);
                   break;
    
              case DECRYPT_DATA:
                   break;
    
              default:
                   // good practice: If you don't know the INStruction, say so:
                   ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
              }
         }
    }
  • 3. Re: Wrong data in installing applet using JCOP
    Adriaan Explorer
    Currently Being Moderated
    Try using RSAPrivateCrtKey, KeyBuilder.TYPE_RSA_CRT_PRIVATE, and KeyBuilder.ALG_RSA_CRT. Some cards only support CRT (Chinese Remainder Theorem) for private keys.

    Adriaan
  • 4. Re: Wrong data in installing applet using JCOP
    919486 Newbie
    Currently Being Moderated
    I also tried that but it did not make any difference.
  • 5. Re: Wrong data in installing applet using JCOP
    Umer Journeyer
    Currently Being Moderated
    Plz try this
    package testPack;
    
    import javacard.framework.APDU;
    import javacard.framework.Applet;
    import javacard.framework.ISO7816;
    import javacard.framework.ISOException;
    import javacard.security.KeyBuilder;
    import javacard.security.KeyPair;
    import javacard.security.RSAPrivateCrtKey;
    import javacard.security.RSAPublicKey;
    import javacardx.crypto.Cipher;
    
    public class TestClass extends Applet {
    
        // This applet is designed to respond to the following
        // class of instructions.
        final static byte GETSET_CLA = (byte) 0x85;
     
        // Instruction set for SimpleString
        final static byte encrypt = (byte) 0x50;
     
        // This buffer contains the string data on the card
        byte TheBuffer[];
     
        // globals
        RSAPrivateCrtKey rsa_PrivateCrtKey;
        RSAPublicKey rsa_PublicKey;
        KeyPair rsa_KeyPair;
        Cipher cipherRSA;
        final short dataOffset = (short) ISO7816.OFFSET_CDATA;
    
        private TestClass(byte bArray[], short bOffset, byte bLength) 
        {
              
    
     
            // generate own rsa_keypair
            rsa_KeyPair = new KeyPair(KeyPair.ALG_RSA_CRT, KeyBuilder.LENGTH_RSA_1024);
            rsa_KeyPair.genKeyPair();
            
            rsa_PublicKey = (RSAPublicKey) rsa_KeyPair.getPublic();
            rsa_PrivateCrtKey = (RSAPrivateCrtKey) rsa_KeyPair.getPrivate();
            
            cipherRSA = Cipher.getInstance(Cipher.ALG_RSA_PKCS1, false);
            
            register(bArray, (short) (bOffset + 1), bArray[bOffset]);
        }
     
        // install
        public static void install(byte bArray[], short bOffset, byte bLength) 
        {
            new TestClass(bArray, bOffset, bLength);
        }
         public void process(APDU apdu) 
         {
              // Good practice: Return 9000 on SELECT
              if (selectingApplet())
              {
                   return;
              }
    
              byte[] buf = apdu.getBuffer();
              
              switch (buf[ISO7816.OFFSET_INS]) 
              {
                   
                   case encrypt:
                        encryptData( apdu );     
                   break;
    
                   default:
                   // good practice: If you don't know the INStruction, say so:
                   ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
              }
         }
         
         private void encryptData(APDU apdu)
         {
              byte[] buffer = apdu.getBuffer();
              short dataLength = apdu.setIncomingAndReceive();
     
              cipherRSA.init(rsa_PublicKey, Cipher.MODE_ENCRYPT);
              short cipherLength = cipherRSA.doFinal(buffer,
                        ISO7816.OFFSET_CDATA, dataLength, buffer, ISO7816.OFFSET_CDATA);
              apdu.setOutgoingAndSend(ISO7816.OFFSET_CDATA, cipherLength);
         }
    
    }
    Trace:
    cm>  /term "Remote|localhost:53362"
    --Opening terminal
    
    /card -a a000000003000000 -c com.ibm.jc.CardManager
    --Waiting for card... ATR=3B E9 00 00 81 31 FE 45 4A 43 4F 50 34 31 56 32    ;....1.EJCOP41V2     32 A7                                              2. ATR: T=1, N=0, IFSC=254, BWI=4/CWI=5, Hist="JCOP41V22" => 00 A4 04 00 08 A0 00 00 00 03 00 00 00 00          .............. (963551 nsec) <= 6F 10 84 08 A0 00 00 00 03 00 00 00 A5 04 9F 65    o..............e     01 FF 90 00                                        .... Status: No Error cm>  set-key 255/1/DES-ECB/404142434445464748494a4b4c4d4e4f 255/2/DES-ECB/404142434445464748494a4b4c4d4e4f 255/3/DES-ECB/404142434445464748494a4b4c4d4e4f cm>  init-update 255 => 80 50 00 00 08 CD 4C 37 F1 B6 3C C8 3B 00          .P....L7..<.;. (2088 usec) <= 00 00 C6 D8 6A 1C B2 02 14 13 FF 02 00 00 93 73    ....j..........s     3A B8 2C 0F F7 C4 77 6F 0A 81 68 57 90 00          :.,...wo..hW.. Status: No Error cm>  ext-auth plain => 84 82 00 00 10 DD AF 1B E7 D5 16 63 FB 3F 96 30    ...........c.?.0     8C 96 33 FD 30                                     ..3.0 (1889 usec) <= 90 00                                              .. Status: No Error cm>  delete 746573742e617070 => 80 E4 00 00 0A 4F 08 74 65 73 74 2E 61 70 70 00    .....O.test.app. (1013 usec) <= 6A 88                                              j. Status: Reference data not found jcshell: Error code: 6a88 (Reference data not found) jcshell: Wrong response APDU: 6A88 Ignoring expected error cm>  delete 746573742e7061636b => 80 E4 00 00 0B 4F 09 74 65 73 74 2E 70 61 63 6B    .....O.test.pack     00                                                 . (1140 usec) <= 6A 88                                              j. Status: Reference data not found jcshell: Error code: 6a88 (Reference data not found) jcshell: Wrong response APDU: 6A88 Ignoring expected error cm>  upload "E:\eclipse-jee-helios-SR1-win32\w\Test\bin\testPack\javacard\testPack.cap" => 80 E6 02 00 16 09 74 65 73 74 2E 70 61 63 6B 08    ......test.pack.     A0 00 00 00 03 00 00 00 00 00 00 00                ............ (1699 usec) <= 00 90 00                                           ... Status: No Error => 80 E8 00 00 FF C4 82 01 D8 01 00 1C DE CA FF ED    ................     02 02 04 00 01 09 74 65 73 74 2E 70 61 63 6B 08    ......test.pack.     74 65 73 74 50 61 63 6B 02 00 21 00 1C 00 21 00    testPack..!...!.     0C 00 1F 00 6A 00 0E 00 AE 00 0A 00 25 00 00 00    ....j.......%...     DB 03 D5 00 00 00 00 00 00 03 01 00 04 00 1F 03    ................     02 01 07 A0 00 00 00 62 01 01 02 01 07 A0 00 00    .......b........     00 62 01 02 02 01 07 A0 00 00 00 62 02 01 03 00    .b.........b....     0C 01 08 74 65 73 74 2E 61 70 70 00 52 06 00 0E    ...test.app.R...     00 00 00 80 03 06 00 05 07 01 00 00 00 5E 07 00    .............^..     AE 00 05 40 18 8C 00 0F 18 08 89 04 18 10 64 90    ...@..........d.     0B 87 01 18 8F 00 11 3D 05 11 04 00 8C 00 0A 87    .......=........     03 AD 03 8B 00 19 18 AD 03 8B 00 17 94 00 00 15    ................     87 05 18 AD 03 8B 00 06 94 00 00 14 87 00 18 10    ................     0A 03 8D 00 12 87 02 18 19 1E 04 41 19 1E 25 8B    ...........A..%.     00 10 7A 04 30 8F 00 07 18 1D 1E 8C 00 16 7A 02    ..z.0.........z.     21 18 8B 00 13 60 03 7A 19 8B 00 0D 2D 1A 04 25    !....`.z....-..%     73 00 10 00 00                                     s.... (5623 usec) <= 00 90 00                                           ... Status: No Error => 80 E8 80 01 DD 50 00 50 00 09 18 19 8C 00 0B 70    .....P.P.......p     08 11 6D 00 8D 00 0E 7A 06 23 19 8B 00 0D 2D 19    ..m....z.#....-.     8B 00 18 32 AD 02 AD 05 05 8B 00 08 AD 02 1A 08    ...2............     1F 1A 08 8B 00 09 29 04 19 08 16 04 8B 00 0C 7A    ......)........z     08 00 0A 00 00 00 00 00 00 00 00 00 00 05 00 6A    ...............j     00 1A 02 00 02 01 02 00 02 00 02 00 02 04 02 00    ................     02 03 02 00 02 05 02 00 02 02 03 81 10 02 01 00    ................     02 00 03 82 01 03 03 82 01 01 06 81 10 00 06 00    ................     00 86 03 80 0A 08 03 80 0A 01 06 80 07 01 06 80    ................     03 00 03 80 03 02 01 81 10 00 06 82 01 00 03 80    ................     03 03 01 81 07 00 01 81 09 00 06 00 00 01 03 81    ................     10 03 03 80 0A 06 03 81 10 01 09 00 25 00 0C 0A    ............%...     07 0E 02 06 09 03 09 09 4E 02 06 00 15 05 0F 08    ........N.......     07 06 04 08 04 09 0D 06 06 07 07 12 08 07 05 09    ................     0A 09 00                                           ... (15136 usec) <= 00 90 00                                           ... Status: No Error Load report:   476 bytes loaded in 0.0 seconds   effective code size on card:       + package AID       9       + applet AIDs       15       + classes           17       + methods           177       + statics           0       + exports           0      ------------------------------         overall           218  bytes cm>  install -i 746573742e617070  -q C9#() 746573742e7061636b 746573742e617070 => 80 E6 0C 00 22 09 74 65 73 74 2E 70 61 63 6B 08    ....".test.pack.     74 65 73 74 2E 61 70 70 08 74 65 73 74 2E 61 70    test.app.test.ap     70 01 00 02 C9 00 00 00                            p....... (351571 usec) <= 90 00                                              .. Status: No Error cm>  card-info => 80 F2 80 00 02 4F 00 00                            .....O.. (790905 nsec) <= 08 A0 00 00 00 03 00 00 00 01 9E 90 00             ............. Status: No Error => 80 F2 40 00 02 4F 00 00                            ..@..O.. (886094 nsec) <= 08 74 65 73 74 2E 61 70 70 07 00 90 00             .test.app.... Status: No Error => 80 F2 10 00 02 4F 00 00                            .....O.. (1921 usec) <= 07 A0 00 00 00 03 53 50 01 00 01 08 A0 00 00 00    ......SP........     03 53 50 41 09 74 65 73 74 2E 70 61 63 6B 01 00    .SPA.test.pack..     01 08 74 65 73 74 2E 61 70 70 90 00                ..test.app.. Status: No Error Card Manager AID   :  A000000003000000 Card Manager state :  OP_READY     Application:  SELECTABLE (--------) "test.app"          Load File  :      LOADED (--------) A0000000035350   (Security Domain)      Module    :                        A000000003535041     Load File  :      LOADED (--------) "test.pack"          Module    :                        "test.app" cm>  /select |test.app => 00 A4 04 00 08 74 65 73 74 2E 61 70 70 00          .....test.app. (529136 nsec) <= 90 00                                              .. Status: No Error cm>  /send 8050000002010200 => 80 50 00 00 02 01 02 00                            .P...... (2403 usec) <= 58 9C C3 4E AB 25 35 FF 17 03 0F B5 9E 91 8A 98    X..N.%5.........     FB 60 5F 8E A0 95 8B 9A 92 B4 B1 2D B9 1F 69 2B    .`_........-..i+     55 C9 41 CD 69 BD 2B 80 86 49 62 C5 A6 C2 58 5D    U.A.i.+..Ib...X]     33 BF AB E8 2F 9A EF 4E FD 95 D1 7E 76 36 B9 DE    3.../..N...~v6..     76 43 8E 1A 8E 13 34 5A FE 69 70 0A 73 D2 42 E4    vC....4Z.ip.s.B.     45 53 FF EB 99 9E B0 4B D4 9B F0 F2 C4 44 3B 0A    ES.....K.....D;.     29 C1 10 86 4F 26 A2 53 65 1F 2F 58 00 97 E7 7B    )...O&.Se./X...{     00 4A 09 AB 27 63 A0 CA 84 6A 89 3E 1F B9 B0 58    .J..'c...j.>...X     90 00                                              .. Status: No Error
    Edited by: Umer on Feb 23, 2012 9:12 PM
  • 6. Re: Wrong data in installing applet using JCOP
    919486 Newbie
    Currently Being Moderated
    Thank you Umer for trying to help.
    I tried your code and it works.
    However I still don't know what was wrong with my code before.
    Any suggestions would be helpful as I'm still learning with Java Card.
  • 7. Re: Wrong data in installing applet using JCOP
    918757 Newbie
    Currently Being Moderated
    I'm not sure but, you initiate your pub and private keys before your KeyPair object generates them. Try to modify these lines :

    private RSAPublicKey keyRSAPublic = (RSAPublicKey) KeyBuilder.buildKey(
              KeyBuilder.TYPE_RSA_PUBLIC, KeyBuilder.LENGTH_RSA_1024, false);
    private RSAPrivateKey keyRSAPrivate = (RSAPrivateKey) KeyBuilder.buildKey(
              KeyBuilder.TYPE_RSA_PRIVATE, KeyBuilder.LENGTH_RSA_1024, false);


    for
    private RSAPublicKey keyRSAPublic = null;
    private RSAPrivateKey keyRSAPrivate = null;
    private KeyPair keyPairRSA = new KeyPair(KeyBuilder.ALG_RSA ,KeyBuildr.LENGTH_RSA_1024);
    and put

    rsa_PublicKey = (RSAPublicKey) rsa_KeyPair.getPublic();
    rsa_PrivateCrtKey = (RSAPrivateCrtKey) rsa_KeyPair.getPrivate();

    into the public EncryptionApp() after you call genkeypair(); methode.
    I think your problem occurs because you call genKeyPair when you already assign public and private keys to your object.

    Hope it solves your problem! good luck

    Edited by: FrancisOL on Feb 23, 2012 1:49 PM

    Edited by: FrancisOL on Feb 23, 2012 1:52 PM

    Edited by: FrancisOL on Feb 23, 2012 1:55 PM

    Edited by: FrancisOL on Feb 23, 2012 1:57 PM
  • 8. Re: Wrong data in installing applet using JCOP
    919486 Newbie
    Currently Being Moderated
    FrancisOL, I think you got a point there.
    But this is what I gathered from the Java Card API documentation:

    buildKey

    public static Key buildKey(byte keyType,
    short keyLength,
    boolean keyEncryption)
    throws CryptoException

    "Creates uninitialized cryptographic keys for signature and cipher algorithms. Only instances created by this method may be the key objects used to initialize instances of Signature, Cipher and KeyPair. Note that the object returned must be cast to their appropriate key type interface."

    So even with the buildKey method were called before, the keys should not be initialized.
  • 9. Re: Wrong data in installing applet using JCOP
    919486 Newbie
    Currently Being Moderated
    As it turned out, you were right Adriaan.
    Some cards only support CRT for private keys. I just did not change the code completely the last time I tried.
    And some can only use ALG_RSA_PKCS1 for encrypt/decrypt data.

    Thank you guys for your help.
  • 10. Re: Wrong data in installing applet using JCOP
    safarmer Expert
    Currently Being Moderated
    Hi,

    KeyBuilder is for creating empty keys to populate with key data, KeyPair can be used to store a public and private key together for grouping or for generating new keys. The method you used to instantiate the key pair was for storing a set of keys not generating them. Even if it works it seems like a convoluted approach. You could just uses keyPair.getPublic() and keyPair.getPrivate() to use the keys.

    My $0.02

    Shane
  • 11. Re: Wrong data in installing applet using JCOP
    Umer Journeyer
    Currently Being Moderated
    safarmer wrote:
    My $0.02
    What is it mean sir ?
  • 12. Re: Wrong data in installing applet using JCOP
    safarmer Expert
    Currently Being Moderated
    http://en.wikipedia.org/wiki/My_two_cents_(idiom)
  • 13. Re: Wrong data in installing applet using JCOP
    Umer Journeyer
    Currently Being Moderated
    hmm nice :-)

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points