是否可以查询 GlobalPlatform 智能卡的剩余持久内存?
我有一个 JavaCard,可以调用 JCSystem.getAvailableMemory(MEMORY_TYPE_PERSISTENT) 并从我的小程序返回该值,但如果它超过 32767 字节,我想要一个准确的值。
I have a JavaCard and can call JCSystem.getAvailableMemory(MEMORY_TYPE_PERSISTENT) and return that from my applet, but I want an exact value if its over 32767 bytes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
支持 GP 2.2 + ETSI 的 Javacard
如果您的卡支持 Global Platform 2.2 和 ETSI,您可以使用 GET DATA 命令。
GP 卡规范 2.2 第 11.3 节规定,
并且在 ETSI 102.226 第 8.2.1.7.2 节中:
成功执行命令后,GET DATA 响应数据字段应按照 GlobalPlatform [4] 中的定义进行编码。命令消息的参考控制参数P1和P2中引用的TLV编码数据对象的值为:
该命令的响应不限于
short
值,因为它使用TLV格式,这意味着您可以检查超过 32767 字节的可用内存Javacard with GP 2.2 + ETSI support
If your card supports Global Platform 2.2 and ETSI, you can use GET DATA command.
GP card spec 2.2 section 11.3 states that
And in ETSI 102.226 section 8.2.1.7.2:
After the successful execution of the command, the GET DATA response data field shall be coded as defined in GlobalPlatform [4]. The value of the TLV coded data object referred to in reference control parameters P1 and P2 of the command message is:
The response of this command is not restricted to
short
value because it is using TLV format, which means you can check free memory that is more than 32767 bytes一般来说,使用标准 Java Card API 不可能从卡中获取准确的可用内存量。由于大多数 Java 卡甚至不支持整数,因此您可以从 API 方法获取的最大值为 32767(有符号短整型的上限)。
如果幸运的话,卡/操作系统制造商可能会提供一些专有的 API 方法。我见过一些来自 NXP JCOP 卡的专有 API,但如果空闲内存量超过了签名短路的上限,那么它们都无法获得可用内存量。
In general there is no possibility to get the exact amount of free memory from the card using the standard Java Card API. Because most Java Cards don't even have integer support, the maximum value you can get from the APIs method is 32767 (upper bound of signed short).
If you're lucky, there might be some proprietary API method from the card/OS manufacturer. I've seen some proprietary APIs from NXP JCOP cards but none of them is capable of getting the amount of free memory if it exceeds the upper bound of a signed short.