I'm an absolute javacard-newbie, so please condone my eventually wrong javacard-comprehension.
I wrote a mini random number generator program. But ist doesen't work.
Code: Select all
import javacard.framework.*;
import javacard.framework.APDU;
import javacard.framework.ISO7816;
import javacard.framework.ISOException;
import javacard.framework.Util;
import javacard.security.RandomData;
public class zufall extends Applet {
/* constants declaration */
// code of CLA byte in the command APDU header
final static byte RANDOM_CLA = (byte) 0x80;
// codes of INS byte in the command APDU header
final static byte random = (byte) 0x20;
RandomData m_rngRandom;
public static void install(byte[] bArray, short bOffset, byte bLength) {
new zufall();
}
/**
* Only this class's install method should create the applet object.
*/
protected zufall() {
register();
}
public void process(APDU apdu) {
byte[] buffer = apdu.getBuffer();
// check SELECT APDU command
if (apdu.isISOInterindustryCLA()) {
if (buffer[ISO7816.OFFSET_INS] == (byte) (0xA4)) {
return;
}
ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
}
// verify the reset of commands have the
// correct CLA byte, which specifies the
// command structure
if (buffer[ISO7816.OFFSET_CLA] != RANDOM_CLA) {
ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
}
switch (buffer[ISO7816.OFFSET_INS]) {
case random:
doRandom(apdu);
return;
default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
} // end of process method
private void doRandom(APDU apdu) {
byte[] buffer=apdu.getBuffer();
byte[] testArray1=new byte[16];
m_rngRandom = RandomData.getInstance(RandomData.ALG_TRNG);
m_rngRandom.nextBytes(testArray1, (short) 0, (short)testArray1.length);
Util.arrayCopyNonAtomic(testArray1, (short)0, buffer, (short)0,(short) testArray1.length);
apdu.setOutgoingAndSend((short)0, (short)testArray1.length);
}
}
my APDU-command:
CMD>//doRandom
0x80 0x20 0x00 0x00 0x00 0x00;
APDU|CLA: 80, INS: 20, P1: 00, P2: 00, Lc: 00, Le: 03, 11, 11, 11, SW1: 6f, SW2: 00
CMD>
"SW1: 6f, SW2: 00" means "Command aborted - more exact diagnosis not possible (e.g., operating system error)."
So what did I wrong?

Ich would be very grateful, if you could give me some information, help or inspiration:)
best regards,
Nina