자바 카드 개발에서 새로운 기능을하고 JavaCard에 NAXOS 프로토콜을 구현하려고합니다. 문제는 변수에 영향을줍니다.자바 카드의 번호에 RSA 암호화를 사용하는 방법
이package RsaEncryption;
import javacard.framework.*;
import javacard.security.KeyBuilder;
import javacard.security.RSAPrivateKey;
import javacardx.crypto.Cipher;
public class RsaEncryption extends Applet {
static final byte PLAIN_CLA = (byte) 0x00;
private RSAPrivateKey privKey;
Cipher cipher;
public static void install(byte[] bArray,short bOffset,byte bLength) {
new RsaEncryption(bArray, bOffset, bLength);
}
private RsaEncryption(byte[] bArray, short bOffset, byte bLength){
register();
}
public boolean select() {
return true;
}
public void deselect() {
}
public void process(APDU apdu) {
if (selectingApplet()) {
return;
}
byte[] buffer = apdu.getBuffer();
apdu.setIncomingAndReceive();
short lenOfData = (short)(buffer[ISO7816.OFFSET_LC]);
byte[] tmp = new byte[lenOfData];
privKey = (RSAPrivateKey) KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_PRIVATE, KeyBuilder.LENGTH_RSA_1024, false);
cipher = Cipher.getInstance(Cipher.ALG_RSA_NOPAD, false);
byte[] G = {0x02};
byte[] P = {0x05};
byte[] x = {0x03};
short maxL = 256;
privKey.setModulus(P, (short)0, maxL);
privKey.setExponent(x, (short)0, maxL);
cipher.init(privKey, Cipher.MODE_DECRYPT);
// Execute G^x mod P using RSA's decrypt
cipher.doFinal(G, (short) 0, maxL, tmp, (short) 0);
// tmp[2] = 0x5;
//buffer[6] = tmp[0];
// buffer[7] = tmp[1];
//Util.arrayCopyNonAtomic(buffer, ISO7816.OFFSET_CDATA, tmp, (short)0, (short)tmp.length);
for(short i=(short)0; i<lenOfData;i++){
buffer[i]= tmp[(short)(i)];
}
//apdu.sendBytesLong(tmp, (short)0, (short)5);
apdu.setOutgoingAndSend((short) 0, (short)tmp.length);
}
}
내가 얻을 출력은
mode_211
enable_trace
establish_context
card_connect -readerNumber 1
select -AID A0000002471201
Command --> 00A4040007A0000002471201
Wrapped command --> 00A4040007A0000002471201
Response <-- 9000
send_apdu -APDU 8000000009010203040506070809FF
Command --> 8000000009010203040506070809FF
Wrapped command --> 8000000009010203040506070809FF
Response <-- 6F00
send_APDU() returns 0x80206F00 (Unknown ISO7816 error: 0x6F00)
당신은 자바 카드에 두 개의 숫자에 전력을 공급하기 위해 다른 방법을 제안 할 수있다 : 내 자바 카드 버전은 나는 그렇게하기 위해 같은 코드를 사용, 2.2.1인가?
'setModulus()'와'setExponent()'를 호출하면 유효하지 않은 길이 ('maxL'은'256'이고 배열은 길이가'1'입니다)를 사용합니다. 128 바이트로'G','P','x'를 사용하고 올바른 결과를 얻기 위해 매우 큰 계수를 사용하십시오 (G^x는 모듈로 5가 될 것입니다). 행운을 빌어 요. ! – vlp
답장을 보내 주셔서 감사합니다. maxL 변수를 1로 변경하고 3이라는 숫자에 2라는 간단한 숫자를 계산해 보았지만 여전히 작동하지 않습니다. – DanoPlurana
128 바이트 길이의'G','P','x'를 시도 했습니까? 배열? – vlp