how to write and read data from smart card using java card apdu

怎甘沉沦 提交于 2019-12-01 11:48:15

问题


I have written an applet and installed it in smart card. But I don't know how to read and write data to smart card?

private void readName(APDU apdu) throws ISOException
{
    byte[] apduBuffer = apdu.getBuffer();
    for (byte i=0; i<userName.length; i++)
    {
        apduBuffer[5+i] = userName[(byte)i] ;
    }
    apdu.setOutgoing();
    apdu.setOutgoingLength((short)userName.length);
    apdu.sendBytes((short)5, (short)userName.length);
}

Is it right code to read data from smart card?

please tell me how to write data to smart card using javacard.


回答1:


Your card is either contact or contactless. Since you say you have already installed the applet, I assume you have the keys to the card.

If so, in order to communicate with your card you will need to do the following:

  1. First authenticate with the Security Domain to which the applet is installed
  2. Select the AID of the applet
  3. use SEND to send data to applet.

And in the response, you will see the bytes you are sending from the Applet:

apdu.setOutgoingLength((short)userName.length);
apdu.sendBytes((short)5, (short)userName.length);

If you need anything more, you will need to provide more details on what you are attempting to accomplish.




回答2:


I found solution.actually I am using eclipse as a editor java card plugin are install in it.when I run program on Smart Card it install latest applet on previous applet every time.To see result we can use pyapdu tool it is very good. thanks for all the response..



来源:https://stackoverflow.com/questions/8264850/how-to-write-and-read-data-from-smart-card-using-java-card-apdu

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