Ich bin ein bisschen neu in Java Card Entwicklung und ich versuche NAXOS-Protokoll auf Javacard und mein Problem ist, an der Macht zu Variablen zu implementieren. Meine Javacard-Version ist 2.2.1, verwende ich einen solchen Code zu tun, dass:Wie man verwendet die RSA-Verschlüsselung an der Macht Zahlen auf Java Card
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);
}
}
Der Ausgang ich erhalte, ist
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)
Können Sie irgendeine andere Art und Weise schlagen zwei Zahlen auf Java Card an die Macht?
Anrufe auf 'setModulus()' und 'setExponent()' ungültige Länge verwenden ('maxL' ist' 256' und die Arrays Länge '1'). Betrachten Sie 'G',' P', 'x' mit 128 Bytes - und verwenden Sie einen sehr großen Modulus, um korrekte Ergebnisse zu erhalten (Ihr G^x wäre modulo 5, was Sie wahrscheinlich nicht wollen) ... viel Glück ! – vlp
Vielen Dank für Ihre Antwort, änderte ich die maxL-Variable auf 1 und versuchte compute einfache Zahlen dh 2 bis 3 und es funktioniert immer noch nicht – DanoPlurana
Haben Sie versucht 128 Byte lang 'G',' P', 'x' Arrays? – vlp