setATRHistBytes() method always returns false

别等时光非礼了梦想. 提交于 2019-12-06 10:41:06

setATRHistBytes(byte[] baBuffer, short sOffset, byte bLength) requires a global array passed as input buffer (baBuffer). See the API documentation:

baBuffer - the source byte array containing the ATR historical bytes. Must be a global array.

A global array is a special array that is managed by the Java Card runtime and accessible by all applets. During the invokation of the process() applet lifecylce method, the only global buffer that you can expect to be available to your Java Card applet is the APDU buffer.

Therefore, you need to copy the contents of HIST_B into the APDU buffer and then pass the APDU buffer into setATRHistBytes():

byte[] buffer = apdu.getBuffer();
Util.arrayCopyNonAtomic(HIST_B, (short)0, buffer, (short)0, (short)HIST_B.length);
boolean changed = GPSystem.setATRHistBytes(buffer, (short)0, (short)HIST_B.length);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!