import javacard.framework.*;
import javacard.security.*;
import javacardx.crypto.*;
public class CardTest extends Applet {

	APDU _writeBackAPDU;//You may delete or rename to use this variable in your methods

	KoreanSEEDKey _writeBackKoreanSEEDKey = (KoreanSEEDKey) KeyBuilder
			.buildKey(KeyBuilder.TYPE_KOREAN_SEED,
					KeyBuilder.LENGTH_KOREAN_SEED_128, false); //You may delete or rename to use this variable in your methods

	public static final byte THIS_CLA = (byte) 0x90;
	public static final byte INITIALIZE_TRANSACTION = (byte) 0x20;
	public static final byte COMPLETE_TRANSACTION = (byte) 0x22;
	public static final byte INITIALIZE_UPDATE = (byte) 0x24;
	public static final byte COMPLETE_UPDATE = (byte) 0x26;
	public static final byte INIT_SEQUENCE[] = {(byte) 0x1, (byte) 0x2};
	public static final byte COMPLETE_SEQUENCE[] = {(byte) 0x1, (byte) 0x3};
	public static final byte INIT_UPDATE_SEQUENCE[] = {(byte) 0x1, (byte) 0x2,
			(byte) 0x3};
	public static final byte COMPLETE_UPDATE_SEQUENCE[] = {(byte) 0x1,
			(byte) 0x1};
	public static void install(byte[] bArray, short bOffset, byte bLength) {
		//install method automatically generated
		new CardTest(bArray, bOffset, bLength);
	}
	protected CardTest(byte[] bArray, short bOffset, byte bLength) {
		//constructor method automatically generated
		register();
	}

	protected void writeBack(APDU apdu, byte[] bytes) {

		//Example in http://www.informit.com/articles/article.aspx?p=25080

		byte buffer[] = apdu.getBuffer();//this method need byte Array Field 

		apdu.setOutgoing();//this method need short Field 

		apdu.sendBytes((short) 0, (short) 3);//this method dont need any Field 

		apdu.sendBytesLong(bytes, (short) 0, (short) 0);//this method dont need any Field 

		_writeBackKoreanSEEDKey.getKey(x, y);//This method needs parameters and byte field.

	}

	public void process(APDU apdu) {
		byte[] buffer = apdu.getBuffer();
		switch (buffer[ISO7816.OFFSET_INS]) {//in the process method all functions are called

			case 1 :
				writeBack(apdu, bytes);
				return;

			default :
				ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
		}
	}

}