SmartCard_入门

package week4;

import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISO7816;
import javacard.framework.ISOException;
import javacard.framework.Util;

public class week4 extends Applet {

	
	byte[] temp = {'h','e','l','l','o'};
	byte[] temp2 = {'h','i'};
	
	public static void install(byte[] bArray, short bOffset, byte bLength) {
		// GP-compliant JavaCard applet registration
		new week4().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
	}

	public void process(APDU apdu) {
		// Good practice: Return 9000 on SELECT
		if (selectingApplet()) {
			return;
		}

		byte[] buf = apdu.getBuffer();
		switch (buf[ISO7816.OFFSET_INS]) {
		case (byte) 0x00:
			Util.arrayCopyNonAtomic(temp,(short)0, buf, (short)0, (short)temp.length);
			apdu.setOutgoingAndSend((short)0,  (short)temp.length);
		    break;
		case (byte) 0x01:
			Util.arrayCopyNonAtomic(temp2,(short)0, buf, (short)0, (short)temp2.length);
			apdu.setOutgoingAndSend((short)0,  (short)temp2.length);
		    break;
		    
		default:
			// good practice: If you don't know the INStruction, say so:
			ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
		}
	}

}





cm>  /select 133541560006
 => 00 A4 04 00 06 13 35 41 56 00 06 00                ......5AV...
 (492941 nsec)
 <= 90 00                                              ..
Status: No Error
cm>  /send 0000010200
 => 00 00 01 02 00                                     .....
 (468888 nsec)
 <= 68 65 6C 6C 6F 90 00                               hello..
Status: No Error
cm>  /send 0001010200
 => 00 01 01 02 00                                     .....
 (398010 nsec)
 <= 68 69 90 00                                        hi..
Status: No Error


你可能感兴趣的:(SmartCard_入门)