如何使用java卡向智能卡写入数据?举例说明

发布于 2024-12-18 05:53:32 字数 375 浏览 5 评论 0原文

有人可以告诉我如何使用java卡在智能卡中写入数据吗? 我有这个代码 我正在使用java卡2.2

private void writeName(APDU apdu) throws ISOException
{ 
    apdu.setIncomingAndReceive();
    byte[] apduBuffer = apdu.getBuffer();

    byte j = (byte)apduBuffer[4];

    userName = new byte[j];
    for (byte i=0; i<j; i++)
    {
        userName[(byte)i] = (byte)apduBuffer[5+i];
    }
}

can some one tell me how to write data in smart card using java card?
i have this code
i am using java card 2.2

private void writeName(APDU apdu) throws ISOException
{ 
    apdu.setIncomingAndReceive();
    byte[] apduBuffer = apdu.getBuffer();

    byte j = (byte)apduBuffer[4];

    userName = new byte[j];
    for (byte i=0; i<j; i++)
    {
        userName[(byte)i] = (byte)apduBuffer[5+i];
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暗地喜欢 2024-12-25 05:53:32

如果您使用 JCOP 插件来开发 Applet,您可以在 bin/ 目录中看到每个包的 .CAP 文件。现在您需要按照依赖关系的顺序安装每个包。假设您的应用程序由包 A、B 和 C 组成,而您的小程序位于 C 包中。 B 导入 A,C 导入 B。

您需要安装软件包的顺序是 A、B、C。使用 JCOP,可以通过以下方式完成此操作:

cm> install <pkgAID> package.cap

一旦对三个软件包完成了此操作,您将需要安装小程序。这可以通过以下方式完成:

cm> install -q <install params> <pkgAID> <AppletAID> packageC.cap

一旦执行此操作,您将看到小程序处于 SELECTABLE 状态。您的 JCOP shell 控制台将如下所示:

Card Manager AID   :  A000000003000000
Card Manager state :  SECURED

    Application:  SELECTABLE (--------) A00000008710015553
    Application:  SELECTABLE (--------) "2PAY.SYS.DDF01"
    Application:  SELECTABLE (--------) A0004D6946617265
    Application:  SELECTABLE (--------) A0000000041010  

所有这些“模块”(库)包都显示如下:

    Load File  :      LOADED (--------) A0000002994E6F53
     Module    :                        A0000002994E6F53656C656374
    Load File  :      LOADED (--------) A0000002990410  
     Module    :                        A00000029904101045

所有处于 SELECTABLE 状态的小程序现在都可以被选择并与之交互。如果您想使用 A00000008710015553 向 Applet 发送数据,则需要先选择它。交互如下图:

cm>  /select A00000008710015553
 => 00 A4 04 00 09 A0 00 00 00 87 10 01 55 53 00       ............US.
 (5273 usec)
 <= 90 00                                              ..
Status: No Error

现在,您可以使用send 命令向上述Applet 发送数据:

cm>  /send 00200000043131313100
 => 00 20 00 00 04 31 31 31 31 00                      . ...1111.
 (34423 usec)
 <= 90 00                                              ..
Status: No Error

这些都是标准的GP 命令。我假设您使用的是 GP 兼容卡;不过你什么也没提到。

我个人认为,在进一步深入研究之前,您需要仔细阅读一下 JC 运行时环境和 JC VM 的工作原理以及它与 API 和一些 GP 规范的关系。

If you are using JCOP plugin for developing the Applet, you can see .CAP files in the bin/ directory for each package. Now you will need to install each package in order of dependency. Suppose your application consists of packages A, B and C with your applet in C package. And B imports A and C imports B.

The order in which you will need to install the packages are A,B,C. Using JCOP, this can be accomplished by:

cm> install <pkgAID> package.cap

Once you have done this for the three packages, you will need to install the applet. This can be accomplished by:

cm> install -q <install params> <pkgAID> <AppletAID> packageC.cap

Once you do this you will see the applet in SELECTABLE state. Your JCOP shell console would look like :

Card Manager AID   :  A000000003000000
Card Manager state :  SECURED

    Application:  SELECTABLE (--------) A00000008710015553
    Application:  SELECTABLE (--------) "2PAY.SYS.DDF01"
    Application:  SELECTABLE (--------) A0004D6946617265
    Application:  SELECTABLE (--------) A0000000041010  

And all those packages that are "modules" (libraries) are shown like this:

    Load File  :      LOADED (--------) A0000002994E6F53
     Module    :                        A0000002994E6F53656C656374
    Load File  :      LOADED (--------) A0000002990410  
     Module    :                        A00000029904101045

All those applets ini SELECTABLE state can now be selected and interacted with. If you want to send data to Applet with A00000008710015553, you will need to first select it. The interaction would be as shown below:

cm>  /select A00000008710015553
 => 00 A4 04 00 09 A0 00 00 00 87 10 01 55 53 00       ............US.
 (5273 usec)
 <= 90 00                                              ..
Status: No Error

Now, you can send data to the above Applet by using send command:

cm>  /send 00200000043131313100
 => 00 20 00 00 04 31 31 31 31 00                      . ...1111.
 (34423 usec)
 <= 90 00                                              ..
Status: No Error

These are all standard GP commands. I assumed that you are using a GP compliant card; you have mentioned nothing about it though.

I personally feel you will need to read through a bit on how JC Runtime Environment and JC VM works and it's relation with the API and a bit of GP spec before you delve into further.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文