如何在javacard上存储数据?
我正在尝试 JavaCard 小程序 - 它是非常简单的 SCWS serverlet(基本上是来自 Gemalto Dev Suite 的模板)。我希望它在卡上存储一些数据 - 如何做?我只找到了一些关于线性和循环文件的理论资料。
//编辑
我设法找到这样的东西:
private byte createfile()
{
try{
AdminFileView uiccAdminFileView = AdminFileViewBuilder.getTheUICCAdminFileView(JCSystem.CLEAR_ON_RESET);
if(uiccAdminFileView == null){
return 'a';
}
uiccAdminFileView.select((short)0x7F60);
EditHandler editHandler = (EditHandler) HandlerBuilder.buildTLVHandler(HandlerBuilder.EDIT_HANDLER,
(short) 50);
editHandler.clear();
editHandler.appendArray(CreateEF, (short) 0,(short) CreateEF.length);
uiccAdminFileView.createFile(editHandler);
data[0] = (byte) 0x12;
data[1] = (byte) 0x34;
data[2] = (byte) 0x56;
uiccAdminFileView.select((short)0xEE00);
uiccAdminFileView.updateBinary((short) 0, data, (short)0, (short)3);
} catch(UICCException e){
return (byte)e.getReason();
}
return 'b';
}
但此时它每次都会返回“a” - 据我所知它与小程序的访问权限有关。
I'm experimenting with applet for JavaCard - it's very simple SCWS serverlet(basically template from Gemalto Dev Suite). I want it to store some data on card - how to do it? I found only some theoretical materials about linear and cyclical files.
//EDIT
I managed to find something like this:
private byte createfile()
{
try{
AdminFileView uiccAdminFileView = AdminFileViewBuilder.getTheUICCAdminFileView(JCSystem.CLEAR_ON_RESET);
if(uiccAdminFileView == null){
return 'a';
}
uiccAdminFileView.select((short)0x7F60);
EditHandler editHandler = (EditHandler) HandlerBuilder.buildTLVHandler(HandlerBuilder.EDIT_HANDLER,
(short) 50);
editHandler.clear();
editHandler.appendArray(CreateEF, (short) 0,(short) CreateEF.length);
uiccAdminFileView.createFile(editHandler);
data[0] = (byte) 0x12;
data[1] = (byte) 0x34;
data[2] = (byte) 0x56;
uiccAdminFileView.select((short)0xEE00);
uiccAdminFileView.updateBinary((short) 0, data, (short)0, (short)3);
} catch(UICCException e){
return (byte)e.getReason();
}
return 'b';
}
But at this point it returns "a" every time - as far as I know it has something to do with access rights for applet.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Java Card 中曾经有一个基于 ISO 7816-4 文件的 API,但它已经沉没很久很久了。现在你只需要自己编程即可。您至少需要方便的 ISO 7816-4 (2005) 标准才能使任何内容与基于文件的卡远程兼容。
当您必须通过安全消息通道从超过 32K 的偏移量发送文件数据,同时密切关注文件选择和访问权限时,真正的“乐趣”就开始了。对于任何阅读这个老问题答案的人来说:祝你好运 - 并且知道它可以完成。
Once there was an ISO 7816-4 file based API in Java Card, but that has been sunk a long long time ago. Now you just have to program it yourself. You need at least the ISO 7816-4 (2005) standard handy to make anything remotely compatible with file based cards.
The real "fun" starts when you have to send file data from an offset of over 32K over a secure messaging channel while keeping an eye on file selection and access rights. For anybody reading the answer to this old question: good luck - and know it can be done.
对于“真正的”智能卡,您可以通过称为 APDU 命令的标准来创建/编辑/删除数据。为此,卡上必须安装一个能够处理 APDU 来创建/更新/读取文件等的操作系统。如果该卡完全是原始的(即它内部实际上没有任何内容),则必须使用该卡的API 或阅读规范并自行完成所有操作(很可能您将处理汇编)。我不知道你的卡是什么,所以无法给出具体说明,请阅读你的手册。
For a "real" smart card, you create/edit/delete data either via something standard called APDU command. For this to work, there must be an OS installed on the card capable of handling the APDU to create/update/read files, etc. If the card is totally virgin (i.e. it has really nothing inside), you have to use the card's API or read the spec and do everything yourself (very likely you'll deal with assembly). I don't know what your card is so I can't give specific instructions, read your manual.
看来您的问题在这里得到了解答:
http://developer.gemalto.com/nc/forums.html?view=single_thread&cat_uid=3&conf_uid=2&thread_uid=154
It seems that your issue is answered here:
http://developer.gemalto.com/nc/forums.html?view=single_thread&cat_uid=3&conf_uid=2&thread_uid=154