getModulus and getExponent return error 6f00

I try to generate a RSA1024-Keypair on a JCOP-31 JavaCard. I thought all my used components are supported, but getting this error 6f00 I am not so sure any more.

Here is some of my code:

private RSAPrivateCrtKey PrivateRSAKey1024;

private RSAPublicKey PublicRSAKey1024;

private KeyPair keypair;

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

keypair.genKeyPair();

PrivateRSAKey1024 = (RSAPrivateCrtKey)keypair.getPrivate();

PublicRSAKey1024 = (RSAPublicKey)keypair.getPublic();

privatevoid getPublicKey(APDU apdu){

byte[] apduBuffer = apdu.getBuffer();

// get the element type and length

bytekeyElement = (byte)(apduBuffer[ISO7816.OFFSET_P2] & 0xFF);

// check correct type (modulus or exponent)

if((keyElement != 0x00) && (keyElement != 0x01))

ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);

// check elements request

byte[] temp =newbyte[4];

byte[] tempMod =newbyte[128];

if(keyElement == 0){

// retrieve modulus

apduBuffer[0] = (byte)((RSAPublicKey)PublicRSAKey1024).getModulus(temp, (short)1);

}else

// retrieve exponent

apduBuffer[0] = (byte)((RSAPublicKey)PublicRSAKey1024).getExponent(tempMod, (short)1);

// send the key element

apdu.setOutgoingAndSend((short)0, (short)((apduBuffer[0] & 0xFF) + 1));

}

Regards, Susanne

[2551 byte] By [susikaufmanna] at [2007-11-27 6:49:34]
# 1
The SW 0x6F00 is thrown if there is an uncaught exception. Use try/catch to localize the method that throws the exception.
lexdabeara at 2007-7-12 18:23:20 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 2

Thank you for the hint. The error gets really strange: aren't I allowed to store more than 4 methods on a card?

I have

final static byte VERIFY = (byte) 0x20;

final static byte GET_FIRSTNAME = (byte) 0x30;

final static byte GET_LASTNAME = (byte) 0x40;

final static byte GET_TITLE = (byte) 0x50;

final static byte GET_PUBLIC_KEY = (byte) 0x60;

The 0x60 is not working (I also tried others like 0x45, 0xCA...). When I change the byte of my GET_PUBLIC_KEY with the GET_TITLE one, suddenly GET_PUBLIC_KEY works (with the adress 0x50), but GET_TITLE (with 0x60) is not working any more.

Any suggestions?

Regards,

Susanne

susikaufmanna at 2007-7-12 18:23:20 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 3
Ok, forget the last post....was my mistake :)
susikaufmanna at 2007-7-12 18:23:20 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 4
Avoid the use of the GP instructions. 0x50 is for example the INITIALIZE UPDATE instruction.Did you localize your exception?
lexdabeara at 2007-7-12 18:23:20 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 5
Are you sure your card supports RSA?
yagmura at 2007-7-12 18:23:20 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 6
Yes, it supports RSA. The only failure was an update of the AID, that I had forgotten. Regars, Susanne
susikaufmanna at 2007-7-12 18:23:20 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 7

6f00 means unknown exception. For me this usually happens when I get NullPointer or ArrayIndexOutOfBounds. Now, in your code there is a clear mistake:

.... temp = new byte[4]

tempMod = new byte[128]

so far so good. But now you call the wrong methods

getExponent(tempMod, ...)

getModulus(temp, ...)

It should be the other way round - public exponent is 3 bytes long, modulus is 128 bytes. Hence an index out of bounds.

Woja at 2007-7-12 18:23:20 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 8
Also, since you start from index 1 in get methods, your tempMod should be 129 bytes.
Woja at 2007-7-12 18:23:20 > top of Java-index,Java Mobility Forums,Consumer and Commerce...