Reputation: 17
Below is DES encryption code. I am getting error 0x6999: "Applet selection failed".
package JCardDES;
import javacard.framework.*;
import javacard.security.*;
import javacardx.crypto.*;
public class JCard_DES extends Applet
{
// globals
DESKey deskey;
Cipher cipherCBC;
final short dataOffset = (short) ISO7816.OFFSET_CDATA;
static byte[] TrippleDESKey = {(byte) 0x38, (byte) 0x12, (byte) 0xA4,
(byte) 0x19, (byte) 0xC6, (byte) 0x3B, (byte) 0xE7, (byte) 0x71, (byte) 0x00, (byte) 0x12, (byte) 0x00,
(byte) 0x19, (byte) 0x80, (byte) 0x3B, (byte) 0xE7, (byte) 0x71, (byte) 0x01, (byte) 0x12, (byte) 0x01,
(byte) 0x01, (byte) 0x01, (byte) 0x03, (byte) 0xE7, (byte) 0x71};
// constructor,
// initialization
private JCard_DES(byte bArray[], short bOffset, byte bLength)
{
try {
deskey = (DESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_DES, KeyBuilder.LENGTH_DES3_3KEY, false);
cipherCBC = Cipher.getInstance(Cipher.ALG_DES_CBC_NOPAD, false);
}
catch (CryptoException e) {
ISOException.throwIt((short) ((short) 0x9000 + e.getReason()));
}
if (bArray[bOffset] == 0)
{
register();
}
else
{
register(bArray, (short)(bOffset+1), bArray[bOffset]);
}
}
// install
public static void install(byte bArray[], short bOffset, byte bLength)
{
new JCard_DES(bArray, bOffset, bLength);
}
public void process(APDU apdu)
{
byte[] buf = apdu.getBuffer();
if (selectingApplet())
{
return;
}
doTrippeDES(apdu);
}
// DES encryption
private void doTrippeDES(APDU apdu)
{
byte a[] = apdu.getBuffer();
short incomingLength = (short) (apdu.setIncomingAndReceive());
if (incomingLength != 24) ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
deskey.setKey(TrippleDESKey, (short)0);
cipherCBC.init(deskey, Cipher.MODE_ENCRYPT,new byte[]{0,0,0,0,0,0,0,0},(short)0,(short)8);
cipherCBC.doFinal(a, (short) dataOffset, incomingLength, a, (short) (dataOffset + 24));
cipherCBC.init(deskey, Cipher.MODE_DECRYPT,new byte[]{0,0,0,0,0,0,0,0},(short)0,(short)8);
cipherCBC.doFinal(a, (short) (dataOffset + 24), incomingLength, a, (short) (dataOffset + 48));
// send results
apdu.setOutgoing();
apdu.setOutgoingLength((short) 72);
apdu.sendBytesLong(a, (short) dataOffset, (short) 72);
}
}
That's strange, because without the initialization codes in try/catch block, there is no problem to select the applet.
My script file (APDU script) is
powerup;
// Select JCard_DES
0x00 0xA4 0x04 0x00 0X06 0XFC 0X74 0X41 0XA1 0X9B 0X63 0x7F;
Please guide me where i'm going wrong since i'm new to Java Card Programming
Thanks
Upvotes: 1
Views: 1104
Reputation: 46
error code 0x6999 means applet selection failed.To determine the correctness of your aid and uniqueness.Pay attention to rules inside sometimes choose aid will appear automatically when the concept of completion.
Upvotes: 0
Reputation: 4047
Your command length (Lc) is incorrect. It should be 0x07
instead of 0x06
.
0x00 0xA4 0x04 0x00 0X07 0XFC 0X74 0X41 0XA1 0X9B 0X63 0x7F
Upvotes: 0