2014-05-01 3 views
0

JCard 프로그래밍 초보자입니다. (2 일 경험 ...) RSA KeyPair를 생성하고 일반인에게 보내는 CREF 에뮬레이트 된 카드에 앱을 배포하려고합니다. 나는 클라이언트 응용 프로그램에서 init 메소드를 실행하면 호스트 RMI 클라이언트 응용 프로그램을 통해 키, 어떻게 든이 예외가 얻을 :RSA 키 생성이 JCARD 2.2.2에서 실패합니다.

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; 
    } 
} 
: 여기

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) 

및 호출되는 내 JCard 애플릿의 코드입니다

아무도 내가 여기서 잘못하고있는 것을 지적 할 수 있습니까?

추신 : 저는 기본적인 것들을 이미 시도해 보았습니다. Jcard에 변수가 있고 그것을 증가시키고 설정하고 설정하는 것처럼 잘 작동했습니다.

답변

2

JCDK User's Guide (for JC 2.2.2) CREF 상기 (C 언어 RE)의 구현은 다음 alogirthms을 지원

  • 112-, 128-, 160- 192 비트 ECC
  • 512 비트 RSA 따라서

라인

rsa_KeyPair = new KeyPair(KeyPair.ALG_RSA, KeyBuilder.LENGTH_RSA_2048); 
01,235,

은 CREF에서 실행될 때 CryptoException.NO_SUCH_ALGORITHM을 던져야합니다 (CREF는 2048 비트 RSA를 지원하지 않으므로). 해당 오류 게다가

, 즉 코드는 적어도 하나 이상의 문제를 가지고, 가능성이 당신이 얻을 예외의 원인입니다 : 여기

byte[] ret = null; 
rsa_PublicKey.getModulus(ret, (short) 0); 
rsa_PublicKey.getExponent(ret, (short) (ret.length + 1)); 

당신은 버퍼 retnull에 있지만 다음 채우기 위해 시도를 초기화 계수와 지수를 버퍼에 저장한다. 이 두 가지 방법 (getModulus()getExponent())은 해당 버퍼를 생성하지 않습니다. 대신 적절한 크기의 버퍼 만들어야합니다

byte[] buffer = new byte[expected_length]; // Note that you certainly do not want to allocate that buffer within your getPub method! 

을 그리고 당신은 그 버퍼에 계수를 작성하고 지수입니다 수 있습니다

byte modLen = rsa_PublicKey.getModulus(buffer, (short) 0); 
byte expLen = rsa_PublicKey.getExponent(buffer, (short) modLen); 
+0

감사합니다! 너는 생명의 은인이야. –