is it possible to return some data along with the status word 9000 on selecting an applet in javacard?

情到浓时终转凉″ 提交于 2019-12-13 14:34:47

问题


i was wondering if i could send back some data from the javacard applet when it is selected.

since select() method returns a boolean value i don't know how to return data bytes from it.

can anyone help me with this? i want the applet to return a simple byte array along with the status word 9000 (which is default for success), when i send the select command to the card.

ie, when i send the following command

00A4040006010203040506

i want a response like,

010203049000

(first four bytes are the data returned from the applet) TIA. thanks in advance..


回答1:


I guess you do the "good practice" of "if selectingApplet() then return" in process? You need to process the incoming APDU instead of simple return.

You can return data to select the normal way, but be careful to return 0x9000 if the select was successful.




回答2:


Yes it is possible to return data during applet selection.

The select() method is normally called by the platform during applet selection. You can do some logic inside this method and return true if you want your applet to be selected or false if not. After calling this method, if your applet was successfully selected, the platform will then call the APDU.process method where you can handle the Select command like any other APDU commands in your applet.

However, your command APDU should indicate an Le field if you want a response data. You can change your command APDU to 00 A4 04 00 06 01 02 03 04 05 06 00 to return all the response data available.

As for returning 9000, just make sure to exit the APDU.process method without throwing an exception or you can throw an ISOException with 9000 value. I prefer the former.



来源:https://stackoverflow.com/questions/28030205/is-it-possible-to-return-some-data-along-with-the-status-word-9000-on-selecting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!