Failed to generate RSA Key
Posted: 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:
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
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)