JavaCard Applet Development Related Questions and Answers.
-
jbsoft
- Posts: 11
- Joined: Tue May 03, 2016 3:37 am
- Points :140
-
Contact:
Post
by jbsoft » Sun Aug 20, 2017 11:50 pm
I need to generates a pair of 2048 bytes keys with the RSA alg in my applet. The APDU response is expected to be the 256 bytes of the public modulus and SW1-SW2 9000. But It returned 0x6F00. I don't know where I made mistake. Could anyone give me some clues and help me out? My code is shown below.
Code: Select all
import javacard.framework.*;
import javacard.security.*;
import javacardx.crypto.*;
public class RSA extends Applet {
public static final byte INS_GEN_KEYS = 0x46;
private static Key privateKey;
public static Key publicKey;
private static KeyPair keyPair;
private RSA() {
}
public static void install(byte bArray[], short bOffset, byte bLength)
throws ISOException {
(new RSA()).register();
}
public void process(APDU apdu) throws ISOException {
byte[] buffer = apdu.getBuffer();
if (selectingApplet()) return ;
switch(buffer[ISO7816.OFFSET_INS])
{
case INS_GEN_KEYS:
genKeys(apdu);
return;
}
}
private void genKeys(APDU apdu) throws CryptoException {
byte[] apduBuffer = apdu.getBuffer();
privateKey = KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_PRIVATE,KeyBuilder.LENGTH_RSA_2048, false);
publicKey = KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_PUBLIC,KeyBuilder.LENGTH_RSA_2048, false);
keyPair = new KeyPair(KeyPair.ALG_RSA, (short)publicKey.getSize());
keyPair.genKeyPair();
publicKey = keyPair.getPublic();
apduBuffer[0] = (byte)((RSAPublicKey)publicKey).getModulus(apduBuffer, (short)1);
apdu.setOutgoing(); // set transmission to outgoing data
apdu.setOutgoingLength((short) apduBuffer.length);
apdu.sendBytesLong(apduBuffer, (short) 0, (short) apduBuffer.length);
}
}
-
Crawford
- Posts: 39
- Joined: Thu Sep 17, 2015 11:50 pm
- Points :246
-
Contact:
Post
by Crawford » Mon Aug 21, 2017 5:13 am
A status word of 0x6F00 is an Unknown Error.
You could try inserting debug code to see what line of code is failing. Add the following line of code near the start and keep moving/redploying and see when you start getting 6F00 instead of 1234.
Code: Select all
ISOException.throwIt((short)0x1234);
-
marjkbadboy
- Posts: 33
- Joined: Fri Jul 31, 2015 2:47 am
- Points :217
-
Contact:
Post
by marjkbadboy » Mon Aug 21, 2017 6:33 am
The problem may be caused by the following several lines of code. Donot use apduBuffer.length for the outgoing length. And If the card does not support extended APDUs, you can't return more than 256 bytes in the response.
Code: Select all
apduBuffer[0] = (byte)((RSAPublicKey)publicKey).getModulus(apduBuffer, (short)1);
apdu.setOutgoing(); // set transmission to outgoing data
apdu.setOutgoingLength((short) apduBuffer.length);
apdu.sendBytesLong(apduBuffer, (short) 0, (short) apduBuffer.length);
It's hunting season!
Users browsing this forum: Google [Bot] and 34 guests
JavaCard OS : Disclaimer
Board Disclaimer
The views and comments posted in these fora are personal and do not necessarily represent the those of the Management of JavaCard OS.
The Management of JavaCard OS does not, under any circumstances whatsoever, accept any responsibility for any advice, or recommentations, made by, or implied by, any member or guest vistor of JavaCard OS that results in any loss whatsoever in any manner to a member of JavaCard OS, or to any other person.
Furthermore, the Management of JavaCard OS is not, and cannot be, responsible for the content of any other Internet site(s) that have been linked to from JavaCard OS.