Ich habe ein Programm geschrieben, um 10
Bytes Zufallszahl mit einem öffentlichen RSA-Schlüssel auf meiner Java Card zu verschlüsseln. Die Zufallszahl wird jedes Mal generiert, wenn die Karte diesen APDU-Befehl empfängt, und da die zugehörige Blockgröße des Chiffrierobjekts 2048 Bit in meinem Applet beträgt, lege ich 242 Byte 0x00
am Ende dieser 10
Byte-Zufallszahl an, um 256
Bytes zu bilden Länge.RSA Encryption löst eine Ausnahme intermittierend auf JavaCard
Das Problem ist, dass manchmal die Antwort eine Crypto Exception mit 05
Wert ist. Wie Sie wissen und wie JC API urkundlich erwähnt:
0x05
= ILLEGAL_USEpublic static final kurze ILLEGAL_USE
Dieser Grund Code verwendet wird zeigen, dass die Unterschrift oder Verschlüsselungsalgorithmus nicht pad die eingehende Nachricht und die Eingabe Nachricht ist nicht Block ausgerichtet.
Da die Eingabe Länge in meinem Applet behoben ist, kann ich mein Problem nicht lösen!
ist hier der entsprechende Teil meines Applets:
protected final void getEncChallenge(APDU apdu) {
random.generateData(generatedChall, (short) 0, (short) 10);
initAsymCipher(ENTITY_BOB, MODE_ENC);
Util.arrayCopy(generatedChall, (short) 0, transientData, (short) 0, (short) 10);
Util.arrayFillNonAtomic(transientData, (short) 10, (short) 246, (byte) 0x00);
rsaCrypto(transientData, persistentData);
apdu.setOutgoing();
apdu.setOutgoingLength((short) 256);
apdu.sendBytesLong(persistentData, (short) 0, (short) 256);
}
protected final void rsaCrypto(byte[] inData, byte[] outData) {
try{
asymCipher.doFinal(inData, (short) 0, (short) 256, outData, (short) 0);
}catch(CryptoException e){
short reason = e.getReason();
ISOException.throwIt((short)(0x6d00 | reason));
}
}
Und hier ist die Antwort:
transientData ---> APDU Response
---------------------------------
80 ..(Eight Random Bytes).. BD ..(246 bytes of "0x00").. ---> OK (i.e. 256 byte encrypted data)
EO ..(Eight Random Bytes).. 64 ..(246 bytes of "0x00").. ---> 6D05
02 ..(Eight Random Bytes).. B3 ..(246 bytes of "0x00").. ---> OK
CB ..(Eight Random Bytes).. 35 ..(246 bytes of "0x00").. ---> 6D05
17 ..(Eight Random Bytes).. 97 ..(246 bytes of "0x00").. ---> OK
0C ..(Eight Random Bytes).. 0C ..(246 bytes of "0x00").. ---> OK
D3 ..(Eight Random Bytes).. 91 ..(246 bytes of "0x00").. ---> 6D05
86 ..(Eight Random Bytes).. E2 ..(246 bytes of "0x00").. ---> OK
C2 ..(Eight Random Bytes).. 23 ..(246 bytes of "0x00").. ---> 6D05
Hat keine Ahnung, jemand, was mit meinem Applet falsch?
Was ALG_ verwenden Sie? – vojta
@vojta 'asymCipher = Cipher.getInstance (Cipher.ALG_RSA_NOPAD, false);' – Abraham