How can I use the security package in JCOP41V2.2?

Hi all, I'm a newbie in javacard programming. I'm trying to develop a project with RSA_signature. But I found, the exception NO_SUCH_ALGORITHM will be thrown out when I new an instance of KeyPair.

My java file Temp_1.java following:

/**

*

*/

package temp;

import javacard.framework.Applet;

import javacard.framework.ISO7816;

import javacard.framework.ISOException;

import javacard.framework.APDU;

import javacard.security.*;

/**

* @author lujj

*

*/

public class Temp_1 extends Applet {

KeyPair myKeyPair = null;

public static void install(byte[] bArray, short bOffset, byte bLength) {

// GP-compliant JavaCard applet registration

new Temp_1().register(bArray, (short) (bOffset + 1), bArray[bOffset]);

}

public void process(APDU apdu) throws ISOException{

// Good practice: Return 9000 on SELECT

if (selectingApplet()) {

return;

}

byte[] buf = apdu.getBuffer();

if(buf[ISO7816.OFFSET_CLA] == (byte)0xEE)

{

try

{

myKeyPair = new KeyPair(KeyPair.ALG_RSA, KeyBuilder.LENGTH_RSA_1024);

}

catch(CryptoException e)

{

ISOException.throwIt((short)(0x6F00+e.getReason()));

}

return;

}

switch (buf[ISO7816.OFFSET_INS]) {

case (byte) 0x00:

break;

default:

// good practice: If you don't know the INStruction, say so:

ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);

}

}

}

************************

This package can be upload and the applet can be installed successfully.

But if I send the apdu "EE 00 00 00 00" after selected the applet, "6F 03" will be returned.

*************************

Is there anyone can help me? Thanks a lot.

[1851 byte] By [Realsomea] at [2007-10-3 10:57:50]
# 1

Try to use ALG_RSA_CRT instead of ALG_RSA like the followings:

myKeyPair = new KeyPair(KeyPair.ALG_RSA_CRT, (short)1024);

By the way, it is not appropriate to construct a new object every time you send a command to the card, because it allocates a new block of memory in EEPROM and there is usually no garbage collection for the un-referred object. It is a good approach to construct all the necessary objects as the applet is installed.

Wei-Chinga at 2007-7-15 6:24:00 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 2

Thank you so much~

Actually, it's only an applet for test. I cannot get the error code if I new the KeyPair in install function or Applet construct function. It will return "6A 80" when install the applet.

And, I found that it support few algorithm. For example, it does not support ALG_DES_MAC4_ISO9797_M2,etc. Is there anything I can do if I want to use the algorithm? Shall I rewrite security package by myself?

5555, security package is the standard package in JAVACARD API 2.1.1.

Realsomea at 2007-7-15 6:24:01 > top of Java-index,Java Mobility Forums,Consumer and Commerce...