apdu.html

来自「JAVA CARD 开发包规格说明,版本为2.2.2」· HTML 代码 · 共 1,404 行 · 第 1/5 页

HTML
1,404
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><!--NewPage--><HTML><HEAD><!-- Generated by javadoc (build 1.5.0_02) on Wed Mar 22 19:19:04 PST 2006 --><TITLE>APDU (Java Card API and Subsets)</TITLE><META NAME="keywords" CONTENT="javacard.framework.APDU class"><LINK REL ="stylesheet" TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style"><SCRIPT type="text/javascript">function windowTitle(){    parent.document.title="APDU (Java Card API and Subsets)";}</SCRIPT><NOSCRIPT></NOSCRIPT></HEAD><BODY BGCOLOR="white" onload="windowTitle();"><!-- ========= START OF TOP NAVBAR ======= --><A NAME="navbar_top"><!-- --></A><A HREF="#skip-navbar_top" title="Skip navigation links"></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY=""><TR><TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"><A NAME="navbar_top_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">  <TR ALIGN="center" VALIGN="top">  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="class-use/APDU.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>  </TR></TABLE></TD><TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM><b>Java Card </b><br><font size="-1">v2.2.2</font></EM></TD></TR><TR><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">&nbsp;<A HREF="../../javacard/framework/AID.html" title="class in javacard.framework"><B>PREV CLASS</B></A>&nbsp;&nbsp;<A HREF="../../javacard/framework/APDUException.html" title="class in javacard.framework"><B>NEXT CLASS</B></A></FONT></TD><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">  <A HREF="../../index.html?javacard/framework/APDU.html" target="_top"><B>FRAMES</B></A>  &nbsp;&nbsp;<A HREF="APDU.html" target="_top"><B>NO FRAMES</B></A>  &nbsp;&nbsp;<SCRIPT type="text/javascript">  <!--  if(window==top) {    document.writeln('<A HREF="../../allclasses-noframe.html"><B>All Classes</B></A>');  }  //--></SCRIPT><NOSCRIPT>  <A HREF="../../allclasses-noframe.html"><B>All Classes</B></A></NOSCRIPT></FONT></TD></TR><TR><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;<A HREF="#field_summary">FIELD</A>&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">DETAIL:&nbsp;<A HREF="#field_detail">FIELD</A>&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD></TR></TABLE><A NAME="skip-navbar_top"></A><!-- ========= END OF TOP NAVBAR ========= --><HR><!-- ======== START OF CLASS DATA ======== --><H2><FONT SIZE="-1">javacard.framework</FONT><BR>Class APDU</H2><PRE><A HREF="../../java/lang/Object.html" title="class in java.lang">java.lang.Object</A>  <IMG SRC="../../resources/inherit.gif" ALT="extended by "><B>javacard.framework.APDU</B></PRE><HR><DL><DT><PRE>public final class <B>APDU</B><DT>extends <A HREF="../../java/lang/Object.html" title="class in java.lang">Object</A></DL></PRE><P>Application Protocol Data Unit (APDU) is the communication format between the card and the off-card applications. The format of the APDU is defined in ISO specification 7816-4.<p> This class only supports messages which conform to the structure of command and response defined in ISO 7816-4. The behavior of messages which use proprietary structure of messages is undefined. This class optionally supports extended length fields but only when the currently selected applet implements the <code>javacardx.apdu.ExtendedLength</code> interface.<p> The <code>APDU</code> object is owned by the Java Card runtime environment. The <code>APDU</code> class maintains a byte array buffer which is used to transfer incoming APDU header and data bytes as well as outgoing data. The buffer length must be at least 133 bytes ( 5 bytes of header and 128 bytes of data ). The Java Card runtime environment must zero out the APDU buffer before each new message received from the CAD.<p> The Java Card runtime environment designates the <code>APDU</code> object as a temporary Java Card runtime environment Entry Point Object (See <em>Runtime Environment Specification for the Java Card Platform</em>, section 6.2.1 for details). A temporary Java Card runtime environment Entry Point Object can be accessed from any applet context. References to these temporary objects cannot be stored in class variables or instance variables or array components. <p>The Java Card runtime environment similarly marks the APDU buffer as a global array (See <em>Runtime Environment Specification for the Java Card Platform</em>, section 6.2.2 for details). A global array can be accessed from any applet context. References to global arrays cannot be stored in class variables or instance variables or array components. <p> The applet receives the <code>APDU</code> instance to process from the Java Card runtime environment in the <code>Applet.process(APDU)</code> method, and the first five header bytes [ CLA, INS, P1, P2, P3 ] are available in the APDU buffer. (The header format is the ISO7816-4 defined 7 byte extended APDU format with a 3 byte Lc field when the Lc field in the incoming APDU header is 3 bytes long).<p> The <code>APDU</code> class API is designed to be transport protocol independent. In other words, applets can use the same APDU methods regardless of whether the underlying protocol in use is T=0 or T=1 (as defined in ISO 7816-3).<p> The incoming APDU data size may be bigger than the APDU buffer size and may therefore need to be read in portions by the applet. Similarly, the outgoing response APDU data size may be bigger than the APDU buffer size and may need to be written in portions by the applet. The <code>APDU</code> class has methods to facilitate this.<p> For sending large byte arrays as response data, the <code>APDU</code> class provides a special method <code>sendBytesLong()</code> which manages the APDU buffer.<p> <pre> // The purpose of this example is to show most of the methods // in use and not to depict any particular APDU processing class MyApplet extends javacard.framework.Applet{ // ... public void process(APDU apdu){  // ...  byte[] buffer = apdu.getBuffer();  byte cla = buffer[ISO7816.OFFSET_CLA];  byte ins = buffer[ISO7816.OFFSET_INS];  ...  // assume this command has incoming data  // Lc tells us the incoming apdu command length  short bytesLeft = (short) (buffer[ISO7816.OFFSET_LC] & 0x00FF);  if (bytesLeft < (short)55) ISOException.throwIt( ISO7816.SW_WRONG_LENGTH );  short readCount = apdu.setIncomingAndReceive();  while ( bytesLeft > 0){      // process bytes in buffer[5] to buffer[readCount+4];      bytesLeft -= readCount;      readCount = apdu.receiveBytes ( ISO7816.OFFSET_CDATA );      }  //  //...  //  // Note that for a short response as in the case illustrated here  // the three APDU method calls shown : setOutgoing(),setOutgoingLength() & sendBytes()  // could be replaced by one APDU method call : setOutgoingAndSend().  // construct the reply APDU  short le = apdu.setOutgoing();  if (le < (short)2) ISOException.throwIt( ISO7816.SW_WRONG_LENGTH );  apdu.setOutgoingLength( (short)3 );  // build response data in apdu.buffer[ 0.. outCount-1 ];  buffer[0] = (byte)1; buffer[1] = (byte)2; buffer[3] = (byte)3;  apdu.sendBytes ( (short)0 , (short)3 );  // return good complete status 90 00  } // ... } </pre> The <code>APDU</code> class also defines a set of <code>STATE_..</code> constants which represent the various processing states of the <code>APDU</code> object based on the methods invoked and the state of the data transfers. The <code>getCurrentState()</code> method returns the current state. <p> Note that the state number assignments are ordered as follows: STATE_INITIAL < STATE_PARTIAL_INCOMING < STATE_FULL_INCOMING < STATE_OUTGOING < STATE_OUTGOING_LENGTH_KNOWN < STATE_PARTIAL_OUTGOING < STATE_FULL_OUTGOING. <p> The following are processing error states and have negative state number assignments : STATE_ERROR_NO_T0_GETRESPONSE, STATE_ERROR_T1_IFD_ABORT, STATE_ERROR_IO and STATE_ERROR_NO_T0_REISSUE. <p>Note:<ul> <li><em>The method descriptions use the ISO7816-4 notation for the various APDU I/O cases of input and output directions. For example - T=0 (Case 2S) protocol - refers to short length outbound only case using the T=0 protocol. The perspective of the notation used in the method descriptions is that of the card(ICC) as seen at the transport layer(TPDU). External transformations of the APDU I/O case may have occurred at the CAD and therefore not visible to the card.</em> </ul><P><P><DL><DT><B>See Also:</B><DD><A HREF="../../javacard/framework/APDUException.html" title="class in javacard.framework"><CODE>APDUException</CODE></A>, <A HREF="../../javacard/framework/ISOException.html" title="class in javacard.framework"><CODE>ISOException</CODE></A></DL><HR><P><!-- =========== FIELD SUMMARY =========== --><A NAME="field_summary"><!-- --></A><TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2"><B>Field Summary</B></FONT></TH></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>static&nbsp;byte</CODE></FONT></TD><TD><CODE><B><A HREF="../../javacard/framework/APDU.html#PROTOCOL_MEDIA_CONTACTLESS_TYPE_A">PROTOCOL_MEDIA_CONTACTLESS_TYPE_A</A></B></CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Transport protocol Media - Contactless Type A</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>static&nbsp;byte</CODE></FONT></TD><TD><CODE><B><A HREF="../../javacard/framework/APDU.html#PROTOCOL_MEDIA_CONTACTLESS_TYPE_B">PROTOCOL_MEDIA_CONTACTLESS_TYPE_B</A></B></CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Transport protocol Media - Contactless Type B</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>static&nbsp;byte</CODE></FONT></TD><TD><CODE><B><A HREF="../../javacard/framework/APDU.html#PROTOCOL_MEDIA_DEFAULT">PROTOCOL_MEDIA_DEFAULT</A></B></CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Transport protocol Media - Contacted Asynchronous Half Duplex</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>static&nbsp;byte</CODE></FONT></TD><TD><CODE><B><A HREF="../../javacard/framework/APDU.html#PROTOCOL_MEDIA_MASK">PROTOCOL_MEDIA_MASK</A></B></CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Media nibble mask in protocol byte</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>static&nbsp;byte</CODE></FONT></TD><TD><CODE><B><A HREF="../../javacard/framework/APDU.html#PROTOCOL_MEDIA_USB">PROTOCOL_MEDIA_USB</A></B></CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Transport protocol Media - USB</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>static&nbsp;byte</CODE></FONT></TD><TD><CODE><B><A HREF="../../javacard/framework/APDU.html#PROTOCOL_T0">PROTOCOL_T0</A></B></CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ISO 7816 transport protocol type T=0.</TD></TR>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?