📄 onewirecontainer16.java
字号:
if (firstPacket == true) { capdu = new CommandAPDU(CLA, ( byte ) 0xA6, ( byte ) 0x01, ( byte ) 0x00, apduBuffer); firstPacket = false; } else { capdu = new CommandAPDU(CLA, ( byte ) 0xA6, ( byte ) 0x02, ( byte ) 0x00, apduBuffer); } rapdu = sendAPDU(capdu, runTime); if (bytesSent < (appletLength + APPLET_FILE_HEADER_SIZE)) { if (rapdu.getSW() != 0x6301) //6301 == Success Packet { bytesSent = appletLength + APPLET_FILE_HEADER_SIZE + 1; } } } if (bytesSent < (appletLength + APPLET_FILE_HEADER_SIZE)) { if (jibComm.doDebugMessages) { System.out.println("One last packet...byteSent: "+bytesSent); System.out.println("Applet length: "+appletBuffer.length); } apduBuffer = new byte [( int ) (appletLength + APPLET_FILE_HEADER_SIZE - bytesSent)]; System.arraycopy(appletBuffer,bytesSent,apduBuffer,0,apduBuffer.length); if (firstPacket == true) { capdu = new CommandAPDU(CLA, ( byte ) 0xA6, ( byte ) 0x01, ( byte ) 0x00, apduBuffer); firstPacket = false; } else { capdu = new CommandAPDU(CLA, ( byte ) 0xA6, ( byte ) 0x02, ( byte ) 0x00, apduBuffer); } rapdu = sendAPDU(capdu, loadRunTime); } return rapdu; } /** * Loads an applet onto this Java iButton. * This method takes an applet filename, directory * and AID. The AID length must NOT exceed <code>AID_SIZE</code>. * * @param fileName file name of the applet to be loaded into this Java iButton * @param directoryName path to the applet to be loaded * @param aid AID of the applet to be loaded * * @return <code>ResponseAPDU</code> indicating success or failure * Possible return values are * <ul> * <li>Success SW 0x9000. * <li>Failure SW 0x6400. Insufficient Memory * <li>Failure SW 0x6901. Invalid AID Length * <li>Failure SW 0x6902. Invalid API Version * <li>Failure SW 0x6903. Invalid Password * <li>Failure SW 0x6904. Invalid Signature Length * <li>Failure SW 0x6905. Hash Corruption * <li>Failure SW 0x6906. Hash Failure * <li>Failure SW 0x6982. Invalid Signature * <li>Failure SW 0x6A84. Class Length Overrun * <li>Failure SW 0x6A86. Invalid Loader Command * <li>Failure SW 0x6A87. Invalid Packet * <li>For additional error codes, please see: * <A HREF="http://www.ibutton.com/jibkit/documents/sw.html"> * http://www.ibutton.com/jibkit/documents/sw.html</A> * </ul> * * @throws FileNotFoundException Applet file not found * @throws IOException Problem reading applet file * @throws IllegalArgumentException Invalid run time value * @throws OneWireException Part could not be found [ fatal ] * @throws OneWireIOException Data wasn't transferred properly [ recoverable ] * * @see #getLoadPINMode * @see #setLoadPINMode */ public ResponseAPDU loadApplet (String fileName, String directoryName, String aid) throws OneWireException, OneWireIOException, IllegalArgumentException, FileNotFoundException, IOException { File appletFile = new File(directoryName, fileName); FileInputStream appletInputStream = new FileInputStream(appletFile); return loadApplet(appletInputStream, aid); } /** * Clears all memory in this Java iButton. The erase will occur at the * beginning of the next command. * * @return <code>ResponseAPDU</code> indicating success or failure * <ul> * <li>Success SW 0x9000. * <li>Failure SW 0x6681. Invalid PIN. * <li>For additional error codes, please see: * <A HREF="http://www.ibutton.com/jibkit/documents/sw.html"> * http://www.ibutton.com/jibkit/documents/sw.html</A> * </ul> * * @throws IllegalArgumentException Invalid run time value * @throws OneWireException Part could not be found [ fatal ] * @throws OneWireIOException Data wasn't transferred properly [ recoverable ] */ public ResponseAPDU masterErase () throws OneWireException, OneWireIOException, IllegalArgumentException { byte[] data; if (password != null) { data = new byte [1 + password.length()]; data [0] = ( byte ) password.length(); System.arraycopy(password.getBytes(), 0, data, 1, password.length()); } else { data = new byte [1]; data [0] = ( byte ) 0; } capdu = new CommandAPDU(CLA, INS, ( byte ) 0x00, ( byte ) 0x00, data); rapdu = sendAPDU(capdu, runTime); return rapdu; } // masterErase() /** * Gets the number of times this Java iButton has been power-on-reset (POR) * since the last master erase. Return value is in little endian * format. No PIN required. * * @return <code>ResponseAPDU</code> indicating success or failure * <ul> * <li>Success SW 0x9000. Data field contains the POR count. * <li>For additional error codes, please see: * <A HREF="http://www.ibutton.com/jibkit/documents/sw.html"> * http://www.ibutton.com/jibkit/documents/sw.html</A> * </ul> * * @throws IllegalArgumentException Invalid run time value * @throws OneWireException Part could not be found [ fatal ] * @throws OneWireIOException Data wasn't transferred properly [ recoverable ] * * @see #masterErase */ public ResponseAPDU getPORCount () throws OneWireException, OneWireIOException, IllegalArgumentException { capdu = new CommandAPDU(CLA, INS, ( byte ) 0x02, ( byte ) 0x00); rapdu = sendAPDU(capdu, runTime); return rapdu; } // getPORCount() /** * Gets the Real Time Clock. No PIN required. * * @return <code>ResponseAPDU</code> containing the value of the real * time clock * <ul> * <li>Success SW 0x9000. * <li>For additional error codes, please see: * <A HREF="http://www.ibutton.com/jibkit/documents/sw.html"> * http://www.ibutton.com/jibkit/documents/sw.html</A> * </ul> * * @throws IllegalArgumentException Invalid run time value * @throws OneWireException Part could not be found [ fatal ] * @throws OneWireIOException Data wasn't transferred properly [ recoverable ] */ public ResponseAPDU getRealTimeClock () throws OneWireException, OneWireIOException, IllegalArgumentException { capdu = new CommandAPDU(CLA, INS, ( byte ) 0x01, ( byte ) 0x0C); rapdu = sendAPDU(capdu, runTime); return rapdu; } // getRealTimeClock() /** * Gets the Answer To Reset (ATR) from this Java iButton. No PIN required. * * @return <code>ResponseAPDU</code> containing the ATR in the data field * <ul> * <li>Success SW 0x9000. * <li>For additional error codes, please see: * <A HREF="http://www.ibutton.com/jibkit/documents/sw.html"> * http://www.ibutton.com/jibkit/documents/sw.html</A> * </ul> * * @throws IllegalArgumentException Invalid run time value * @throws OneWireException Part could not be found [ fatal ] * @throws OneWireIOException Data wasn't transferred properly [ recoverable ] */ public ResponseAPDU getATR () throws OneWireException, OneWireIOException, IllegalArgumentException { capdu = new CommandAPDU(CLA, INS, ( byte ) 0x01, ( byte ) 0x0B); rapdu = sendAPDU(capdu, runTime); return rapdu; } // getATR() /** * Gets the Ephemeral Gabage Collection Mode. * A value of <code>1</code> indicates ephemeral garbage collection * is turned on, <code>0</code> if turned off. No PIN required. * * @return <code>ResponseAPDU</code> containing the Ephemeral Garbage * Collector Mode * <ul> * <li>Success SW 0x9000. * <li>For additional error codes, please see: * <A HREF="http://www.ibutton.com/jibkit/documents/sw.html"> * http://www.ibutton.com/jibkit/documents/sw.html</A> * </ul> * * @throws IllegalArgumentException Invalid run time value * @throws OneWireException Part could not be found [ fatal ] * @throws OneWireIOException Data wasn't transferred properly [ recoverable ] * * @see #setEphemeralGCMode */ public ResponseAPDU getEphemeralGCMode () throws OneWireException, OneWireIOException, IllegalArgumentException { capdu = new CommandAPDU(CLA, INS, ( byte ) 0x01, ( byte ) 0x02); rapdu = sendAPDU(capdu, runTime); return rapdu; } // getEphemeralGCMode() /** * Gets the Applet Garbage Collection Mode. * A value of <code>1</code> indicates applet garbage collection * is turned on, <code>0</code> if turned off. No PIN required. * * @return <code>ResponseAPDU</code> containing the Applet Garbage * Collector Mode * <ul> * <li>Success SW 0x9000. * <li>For additional error codes, please see: * <A HREF="http://www.ibutton.com/jibkit/documents/sw.html"> * http://www.ibutton.com/jibkit/documents/sw.html</A> * </ul> * * @throws IllegalArgumentException Invalid run time value * @throws OneWireException Part could not be found [ fatal ] * @throws OneWireIOException Data wasn't transferred properly [ recoverable ] * * @see #setAppletGCMode */ public ResponseAPDU getAppletGCMode () throws OneWireException, OneWireIOException, IllegalArgumentException { capdu = new CommandAPDU(CLA, INS, ( byte ) 0x01, ( byte ) 0x03); rapdu = sendAPDU(capdu, runTime); return rapdu; } // getAppletGCMode() /** * Gets the Command PIN Mode. * A value of <code>1</code> indicates that a PIN is required for * all Administrative and AID commands, <code>0</code> indicates * free access. No PIN required. * * @return <code>ResponseAPDU</code> containing the Command PIN Mode * <ul> * <li>Success SW 0x9000. * <li>For additional error codes, please see: * <A HREF="http://www.ibutton.com/jibkit/documents/sw.html"> * http://www.ibutton.com/jibkit/documents/sw.html</A> * </ul> * * @throws IllegalArgumentException Invalid run time value * @throws OneWireException Part could not be found [ fatal ] * @throws OneWireIOException Data wasn't transferred properly [ recoverable ] * * @see #setCommandPINMode * @see #setCommonPIN * @see #setPIN */ public ResponseAPDU getCommandPINMode () throws OneWireException, OneWireIOException, IllegalArgumentException { capdu = new CommandAPDU(CLA, INS, ( byte ) 0x01, ( byte ) 0x04); rapdu = sendAPDU(capdu, runTime); return rapdu; } // getCommandPINMode() /** * Gets the Load PIN Mode. * A value of <code>1</code> indicates that a PIN is required for Applet * loading. No PIN required. * * @return <code>ResponseAPDU</code> containing the Load PIN Mode * <ul> * <li>Success SW 0x9000. * <li>For additional error codes, please see: * <A HREF="http://www.ibutton.com/jibkit/documents/sw.html"> * http://www.ibutton.com/jibkit/documents/sw.html</A> * </ul> * * @throws IllegalArgumentException Invalid run time value * @throws OneWireException Part could not be found [ fatal ] * @throws OneWireIOException Data wasn't transferred properly [ recoverable ] * * @see #loadApplet * @see #setLoadPINMode */ public ResponseAPDU getLoadPINMode () throws OneWireException, OneWireIOException, IllegalArgumentException { capdu = new CommandAPDU(CLA, INS, ( byte ) 0x01, ( byte ) 0x05); rapdu = sendAPDU(capdu, runTime); return rapdu; } // getLoadPINMode() /** * Gets the Restore Mode. * When Restore Mode is enabled (<code>1</code>), all field updates and * <code>javacard.framework.System</code> transactions are considered atomic. * If a tear occurs in the middle of these updates, values just * prior to the update are restored. No PIN required. * * @return <code>ResponseAPDU</code> containing the Restore Mode * <ul> * <li>Success SW 0x9000. * <li>For additional error codes, please see: * <A HREF="http://www.ibutton.com/jibkit/documents/sw.html"> * http://www.ibutton.com/jibkit/documents/sw.html</A> * </ul> * * @throws IllegalArgumentException Invalid run time value * @throws OneWireException Part could not be found [ fatal ] * @throws OneWireIOException Data wasn't transferred properly [ recoverable ] * * @see #setRestoreMode */ public ResponseAPDU getRestoreMode ()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -