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.

Failed to generate RSA Key

Algorithm School

Moderator: UNKNwYSHSA

Sajaki
Posts: 11
Joined: Tue Jan 05, 2016 4:51 am
Points :106
Contact:

Failed to generate RSA Key

Post by Sajaki » Fri Feb 19, 2016 5:36 am

I am trying to deploy an application on a CREF emulated card which generates an RSA KeyPair and sends the public key over to the host RMI Client application.

Here is my applet code:

Code: Select all

package sid2;
 
import java.rmi.RemoteException;
 
import javacard.framework.UserException;
import javacard.framework.service.CardRemoteObject;
import javacard.security.*;
import javacardx.crypto.Cipher;
 
public class CompteurImpl extends CardRemoteObject implements ICompteur {
   
    private byte compteur = 120;
    RSAPrivateKey  rsa_PrivateKey;
    RSAPublicKey rsa_PublicKey;
    KeyPair rsa_KeyPair;
    Cipher cipherRSA;
   
    public void setPub(byte[] expo,byte[] mod){
       
        rsa_PublicKey.setExponent(expo, (short)0, (short)expo.length);
        rsa_PublicKey.setModulus(mod, (short)0, (short)mod.length);
    }
   
    public byte[] getPub(){
        byte[] ret = null;
        rsa_PublicKey.getModulus(ret, (short)0);
        rsa_PublicKey.getExponent(ret, (short)(ret.length+1));
       
        return ret;
    }
   
 
    public void initialiser(byte v) throws RemoteException, UserException {
 
        rsa_KeyPair = new KeyPair( KeyPair.ALG_RSA, KeyBuilder.LENGTH_RSA_2048);
        rsa_KeyPair.genKeyPair();
        rsa_PublicKey = (RSAPublicKey) rsa_KeyPair.getPublic();
        rsa_PrivateKey = (RSAPrivateKey) rsa_KeyPair.getPrivate();
        compteur = v;
       
    }
   
}


But when I run the init method from the client application, I get the exception below. Could anyone help me to let me know what is wrong? Thanks

Exception in thread "main" java.lang.UnsatisfiedLinkError: com.sun.javacard.impl.NativeMethods.getCurrentContext()B
at com.sun.javacard.impl.NativeMethods.getCurrentContext(Native Method)
at com.sun.javacard.impl.PrivAccess.getCurrentAppID(PrivAccess.java:454)
at javacard.framework.CardRuntimeException.<init>(CardRuntimeException.java:46)
at javacard.security.CryptoException.<init>(DashoA10*..:25)
at com.sun.javacard.javax.smartcard.rmiclient.CardObjectFactory.throwIt(Unknown Source)
at com.sun.javacard.javax.smartcard.rmiclient.CardObjectFactory.throwException(Unknown Source)
at com.sun.javacard.javax.smartcard.rmiclient.CardObjectFactory.getObject(Unknown Source)
at com.sun.javacard.rmiclientlib.JCRemoteRefImpl.parseAPDU(Unknown Source)
at com.sun.javacard.rmiclientlib.JCRemoteRefImpl.invoke(Unknown Source)
at sid2.CompteurImpl_Stub.initialiser(Unknown Source)
at sid2.ClientRmi.main(ClientRmi.java:36)

User avatar
UNKNwYSHSA
Posts: 630
Joined: Thu May 21, 2015 4:05 am
Points :3053
Contact:

Re: Failed to generate RSA Key

Post by UNKNwYSHSA » Sun Feb 21, 2016 12:57 am

How you run the init method?
sense and simplicity

User avatar
btwtiger
Posts: 28
Joined: Wed Jun 10, 2015 7:22 am
Points :134
Contact:

Re: Failed to generate RSA Key

Post by btwtiger » Mon Feb 22, 2016 3:48 am

You may need to check the documentation, but from memory the CREF emulator only supports 512 bit keys.
Onward...

User avatar
btwtiger
Posts: 28
Joined: Wed Jun 10, 2015 7:22 am
Points :134
Contact:

Re: Failed to generate RSA Key

Post by btwtiger » Mon Feb 22, 2016 3:51 am

The below code also has the issue that you are trying to copy into a null buffer. The method does not allocate memory for you. You need to allocate a buffer, or use a previously allocated buffer.

Code: Select all

 public byte[] getPub(){
        byte[] ret = null;
        rsa_PublicKey.getModulus(ret, (short)0);
        rsa_PublicKey.getExponent(ret, (short)(ret.length+1));
       
        return ret;
    }
Onward...

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 14 guests

JavaCard OS : Disclaimer