⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 265-268.html

📁 Smart Card Developer s Kit, a smart card manual for development, English
💻 HTML
字号:
<!-- Edit EirGrabber 3.01 -->
<HTML>
<HEAD>
<TITLE>Smart Card Developer's Kit:The FlexCash Card: An E-commerce Smart Card Application</TITLE>



<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="262-265.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="../ewtoc.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H4 ALIGN="LEFT"><A NAME="Heading8"></A><FONT COLOR="#000077">The E-Bucks Card-Side Code</FONT></H4>
<P>Listing 11.3 is the new and improved E-Bucks section of the FlexCash smart card program that implements the E-Bucks e-cash protocol. For the sake of clarity, the Java code doesn&#146;t use any encryption.
</P>
<P><B>Listing 11.3.</B> E-Bucks e-cash card-side code.</P>
<PRE>
  case EBUCKS:
    if(Array[0] == (byte)0xE2) &#123;
        // Get EBucks Transaction Number
        _OS.ReadBinaryFile((short)5, (byte)1, EBucks);
        if(Array[1] == (byte)0x02) &#123; // Request Debit
            EBucks[0]&#43;&#43;;
            EBucks[1] = CHALLENGE;
            Status =
                     _OS.WriteBinaryFile((short)5, (byte)1, EBucks);
            _OS.SendMessage(Ack, (byte)1);
            _OS.SendMessage(EBucks, (byte)2);
            _OS.SendStatus(Status);
            continue;
        &#125;
        if(Array[1] == (byte)0x04) &#123; // Make Debit
          _OS.GetMessage(Array, (byte) 0x04, Ack[0]);
          if(Array[0] == EBucks[0] &#38;&#38; // Transaction Number
             Array[1] == CHALLENGE &#38;&#38;
             Array[2] == DEBITFLAG) &#123;
               EBucks[1] = CREDITFLAG;
               EBucks[2] = Array[3]; // Amount
               Value[2] = Ack[0] = (byte)(Value[2]-Array[3]);
               Status = _OS.WriteBinaryFile((short)2,(byte)1, Ack);
               _OS.SendStatus(Status);
               continue;
          &#125; else &#123;
               _OS.SendStatus((byte)0x30);
               continue;
          &#125;
          &#125;
        if(Array[1] == (byte)0x06) &#123; // Request Credit
          if(EBucks[1] == CREDITFLAG) &#123;
             Array[0] = Array[2];  // Transaction Number
             Array[1] = Array[3];  // Challenge
             Array[2] = EBucks[2]; // Amount
             Array[3] = CREDITFLAG;
             EBucks[1] = 0;
            _OS.SendMessage(Ack, (byte)1);
            _OS.SendMessage(Array, (byte)4);
            _OS.SendStatus((byte)0x00);
            continue;
          &#125; else &#123;
            _OS.SendStatus((byte)0x30);
            continue;
          &#125;
        &#125;
    &#125; else &#123; // Unknown E-Bucks command
    _OS.Execute((short)0,(byte)0);
    _OS.SendStatus((byte)0x95);
    continue;
    &#125;
break;
</PRE>
<H4 ALIGN="LEFT"><A NAME="Heading9"></A><FONT COLOR="#000077">The E-Bucks Reader-Side Code</FONT></H4>
<P>To complete our story, Listing 11.4 is a Windows PC program that might run on a vending machine that accepts E-Bucks e-cash cards.
</P>
<P><B>Listing 11.4.</B> E-Bucks e-cash host-side code.</P>
<PRE>
#define DEBITFLAG 1
void CSmartCashDlg::OnSpendebucks()
&#123;
    DWORD dwAmount;

    BYTE bpRequestDebit[]  = &#123;0xE2, 0x02, 0x00, 0x00&#125;;
    BYTE bpMakeDebit[]     = &#123;0xE2, 0x04, 0x00, 0x00,
                                0x00, 0x00, 0x00, 0x00&#125;;
    BYTE bpRequestCredit[] = &#123;0xE2, 0x06, 0x00, 0x00, 0x00&#125;;

    m_EBucks.GetWindowText(cString);
    sscanf((LPCTSTR)cString, "%2d", &#38;dwAmount);

    hresult =
        ExchangeCardMessage(bpRequestDebit, (BYTE)0x04, bpReply, 0x02);
    GetSW(&#38;wSW);

    bpMakeDebit[4] = bpReply[0];
    bpMakeDebit[5] = bpReply[1];
    bpMakeDebit[6] = DEBITFLAG;
    bpMakeDebit[7] = (BYTE)dwAmount;
    hresult = SendCardMessage(bpMakeDebit, (BYTE)0x08);
    GetSW(&#38;wSW);

    hresult =
        ExchangeCardMessage(bpRequestCredit, (BYTE)0x04, bpReply, 0x04);

    if (FAILED(hresult))
        throw (hresult);
    else &#123;
        GetSW(&#38;wSW);
        sprintf(string, "[%04x] %02x %02x %02x %02x",
            wSW, bpReply[0], bpReply[1], bpReply[2], bpReply[3]);
            m_editScardStatus.SetWindowText(string);
    &#125;
&#125;
</PRE>
<H3><A NAME="Heading10"></A><FONT COLOR="#000077">Summary</FONT></H3>
<P>In this chapter, we consider a simple e-commerce smart card application that illustrates writing code to run on a smart card together with some basic security considerations in moving value from the card to the host. Be assured that the protocol used by real e-cash cards such as VisaCash, Mondex, and Proton is much more complicated than this one. But if you are just running a frequent buyer points program for Joe&#146;s Fish Store, then the preceding e-cash protocol would probably provide sufficient security to move Pisces Points between Joe&#146;s cash register and the smart card.
</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="262-265.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="../ewtoc.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>



</BODY></HTML>

⌨️ 快捷键说明

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