Got 0x8888 when transfering RSA public key outside
Posted: Wed Dec 09, 2015 5:44 am
The code below is to generate a RSA key pair and transfer the public key to outside in the APDU response:
But I came across a problem when I transfered RSA public key outside.
When I send the APDU to the card, I got 8888,as shown below:
>> 00 A4 04 00 06 11 22 33 44 55 01
<< 90 00
>> 00 C0 00 00
<< 88 88
Could some body tell me the reason about this?
But I came across a problem when I transfered RSA public key outside.
Code: Select all
public class RSAKEY extends Applet {
private static final boolean NO_EXTERNAL_ACCESS = false;
private static final byte GENERATE_KEY_PAIR = (byte) 0xC0;
RSAPrivateKey thePrivateKey = (RSAPrivateKey) KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_PRIVATE, KeyBuilder.LENGTH_RSA_512, NO_EXTERNAL_ACCESS);
RSAPublicKey thePublickKey = (RSAPublicKey) KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_PUBLIC, KeyBuilder.LENGTH_RSA_512, NO_EXTERNAL_ACCESS);
KeyPair theKeyPair = new KeyPair(thePublickKey, thePrivateKey);
public static void install(byte[] bArray, short bOffset, byte bLength) {
new RSAKEY();
}
protected RSAKEY() {
register();
}
public void process(APDU apdu) {
if (selectingApplet()) {
return;
}
byte[] buffer = apdu.getBuffer();
short privateKeySize = 0;
short publicKeySize = 0;
byte[] publicArray;
byte[] privateArray;
try {
switch (buffer[ISO7816.OFFSET_INS]) {
case GENERATE_KEY_PAIR:
theKeyPair.genKeyPair();
PrivateKey thePrivateKey = theKeyPair.getPrivate();
PublicKey thePublicKey = theKeyPair.getPublic();
publicKeySize = thePrivateKey.getSize();
privateKeySize = thePrivateKey.getSize();
byte[] publicKey = JCSystem.makeTransientByteArray((short) (publicKeySize), JCSystem.CLEAR_ON_DESELECT);
((RSAPublicKey) thePrivateKey).getExponent(publicKey, (short) publicKeySize);
Util.arrayCopyNonAtomic(publicKey, (short) 0, buffer, (short) 0, (short) (publicKeySize ));
apdu.setOutgoingAndSend((short) 0, (short) (publicKeySize));
break;
default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
} catch (Exception e) {
if (e instanceof CryptoException) {
short r = ((CryptoException) e).getReason();
ISOException.throwIt(r);
} else {
ISOException.throwIt((short) 0x8888);
}
}
}
}
When I send the APDU to the card, I got 8888,as shown below:
>> 00 A4 04 00 06 11 22 33 44 55 01
<< 90 00
>> 00 C0 00 00
<< 88 88
Could some body tell me the reason about this?