2017-12-01 26 views
-1

Java Cardアプレット実装でRSA公開鍵モジュラスを取得する際に問題があります。公開512ビットRSAキーを送信するコマンドSEND_PUB(ケースステートメントcase SEND_PUBを参照)ステータスワード6F 00を返します。私の実装で何が間違っていますか?RSA公開鍵モジュラスを取得しようとするとSW 6F 00を受け取る

public class crypto extends Applet { 


    private static final boolean NO_EXTERNAL_ACCESS = false; 
    private static byte[] file=new byte[128]; 
    private static byte[] SignedFile=new byte[20];  
    private static RSAPublicKey p; 
    private static RSAPublicKey publicKey; 
    private static RSAPrivateKey privateKey; 
    private static KeyPair keyPair; 
    Signature sig; 
    private final static byte ALOC= 0x07; //vérifier le code PIN 
    private final static byte INS_PIN= 0x01; //vérifier le code PIN 
    private final static byte INS_PUK= 0x02; //vérifier le code PUK 
    private final static byte UPD_PIN= 0x03; //modifier le code PIN 
    private final static byte RCV_FILE= 0x04; //recvoir le fichier 
    private final static byte SIGNATURE= 0x05; //Récupérer la clé privée 
    private final static byte SEND_PUB= 0x06; //envoyer la la clé publique 

    public static OwnerPIN pin,puk; 

    public static void install(byte[] bArray, short bOffset, byte bLength) { 

     new crypto(); 
    } 


    protected crypto() { 
     register(); 
     puk = new OwnerPIN(nbre_tentative, length); 
     puk.update(code_puk, (short) 0, length); 

     pin = new OwnerPIN(nbre_tentative, length); 
     pin.update(code_pin, (short) 0, length); 


     // publicKey = (RSAPublicKey) KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_PUBLIC,KeyBuilder.LENGTH_RSA_512,true); 
     // keyPair = new KeyPair(KeyPair.ALG_RSA, (short) publicKey.getSize()); 
     // publicKey = (RSAPublicKey) keyPair.getPublic(); 



    KeyPair rsa_KeyPair = new KeyPair(KeyPair.ALG_RSA_CRT, KeyBuilder.LENGTH_RSA_512); 
     rsa_KeyPair.genKeyPair(); 
     RSAPublicKey p = (RSAPublicKey) rsa_KeyPair.getPublic(); 
     //RSAPrivateKey rsa_PrivateCrtKey 0= (RSAPrivateKey) rsa_KeyPair.getPrivate(); 
     // cipherRSA = Cipher.getInstance(Cipher.ALG_RSA_PKCS1, false); 
     } 


    public void process(APDU apdu) { 
     byte[] buffer = apdu.getBuffer(); 
     if(selectingApplet()) 
      return; 
     if(buffer[ISO7816.OFFSET_CLA] != CLA) 
      ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED); 
     switch (buffer[ISO7816.OFFSET_INS]) 
     { 


      case SEND_PUB : 

      //this is to send the modulus 
       p.getModulus(buffer, ISO7816.OFFSET_CDATA); 
       apdu.setOutgoing(); 
       apdu.setOutgoingLength((short) 64); 
       apdu.sendBytesLong(buffer, ISO7816.OFFSET_CDATA, (short) 64); 

       case SIGNATURE : 
        Signature s = Signature.getInstance(Signature.ALG_RSA_SHA_PKCS1, false); 
        s.init(privateKey, Signature.MODE_SIGN); 
        short sigLen = s.sign(file,(short)0, (short)file.length,SignedFile, (short)0);      
        break;  
      default: 
        ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED); 
     } 
    } 
} 
+0

スイッチの最初のケースで '休憩 'がありませんか? – vojta

答えて

2

ラインp.getModulus(...);pにアクセスするとき、あなたがNullPointerExceptionを取得するので、あなたは、ステータスワード6F 00を受けます。これは、インスタンスフィールドpが決して初期化されていないことです(上記の質問に表示されたコードでは少なくともありません)。したがって、nullです。

RSAPublicKey p = (RSAPublicKey) rsa_KeyPair.getPublic(); 

ラインは、インスタンスフィールドpにもpという名前と、このように、インスタンスフィールドを隠しているローカル変数に公開鍵オブジェクトを割り当てていないこと。

+0

私はちょうど私が示したコードで間違っていた、それは問題ではない、助けてください –

+3

@ AymanR'batiその後、実際に使用するコードを表示! 'p'はあなたの更新されたコードではまだ' null'です。 –

関連する問題