从智能卡读取大数据错误标记丢失

时间:2016-11-03 06:40:31

标签: android nfc smartcard

我想通过Android App中的nfc在智能卡中读/写大数据。 根据链接Send more than 261 bytes to Java Card with Android NFC  我可以逐块编写大型apdu。

但是当我想要阅读大数据时,我遇到了问题: 我在android app

中编写了这个用于读取大数据的代码
  public  byte[] ReadCertificate(int keyindex)
{
    byte ReadCertAPDU[]=new byte[5];
    byte Read_Cert_CLA = AppletCLA;
    byte Read_Cert_INS = (byte)0x26;
    byte Read_Cert_P1 = (byte)0x00;
    byte Read_Cert_P2 = (byte)keyindex;
    byte Read_Cert_LE = (byte)0xFF;

    byte[] cert=new byte[2000];
    ReadCertAPDU[0] = Read_Cert_CLA;
    ReadCertAPDU[1] = Read_Cert_INS;
    ReadCertAPDU[2] = Read_Cert_P1;
    ReadCertAPDU[3] = Read_Cert_P2;
    ReadCertAPDU[4] = Read_Cert_LE;

    try {

        byte[] response = transceives(ReadCertAPDU);
        if(response==null)
            return null;

        else {
            if (response[0] == (byte) 0x61)
                response = GetResult2(LogStep, response);
            return response;
        }

    }
    catch (Exception e)
    {
        Log.e( LogStep,e.getMessage()+" IOException on Sent Command: ");
    }
    return  null;

}

我收到错误标记在transceiver()方法中的异常中丢失。当我在pyapdu工具中测试它时我没有问题。我得到数据+ 61FF,我继续发送00c00000ff,我得到结果。但在Android应用程序中我有问题 在我的applet中我有方法:

private void ReadCertificate(APDU apdu)
 {
     byte[] buffer=apdu.getBuffer();
     byte P2=buffer[ISO7816.OFFSET_P2];

     Util.arrayCopyNonAtomic(((byte[])CertificateArray[P2]),(short)0,Certificate, (short) 0,(short)Certificate.length);


    short toSend = (short) Certificate.length; 

    try {
        apdu.setOutgoing();
        apdu.setOutgoingLength(toSend);
        byte counter = 0;
        short senddate;
        while (toSend > 0) {
            if(toSend>255)
                senddate=(short)255;
            else
                senddate=toSend;
            apdu.sendBytesLong(Certificate, (short) (255 * counter), senddate);

            toSend = (short) (toSend - senddate);
            counter = (byte) (counter + 1);
        }
    } 
  catch (Exception e) {

    }
 }

0 个答案:

没有答案