Our Online Store have the new products: RFID antenna board. Currently it can work with JC10M24R and JCOP4 card chips.
Compared with normal cards, the antenna board module has a smaller size and fixed holes, which is easy to integrate in the IOT(Internet Of Things) project.

Issue about generating 2048 bytes keys with RSA

JavaCard Applet Development Related Questions and Answers.
jbsoft
Posts: 11
Joined: Tue May 03, 2016 3:37 am
Points :140
Contact:

Issue about generating 2048 bytes keys with RSA

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:

Re: Issue about generating 2048 bytes keys with RSA

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);

User avatar
marjkbadboy
Posts: 33
Joined: Fri Jul 31, 2015 2:47 am
Points :217
Contact:

Re: Issue about generating 2048 bytes keys with RSA

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!

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 51 guests

JavaCard OS : Disclaimer