コード例 #1
0
  public EidPublicData getPublicData() throws Exception {
    EidPublicData eid = new EidPublicData();

    getProperty1(); // For future analysis
    eid.setIDNumber(this.getIdNumber());
    setPublicData(eid);
    setPublicData(eid);
    return eid;
  }
コード例 #2
0
  private void setPublicData(EidPublicData eid) throws Exception {

    ResponseAPDU response;
    response =
        channel.transmit(
            new CommandAPDU(new byte[] {0x00, (byte) 0xA4, 0x00, 0x00, 0x02, 0x02, 0x03}));
    if (response.getSW1() != 0x61) throw new Exception("Failed");
    response =
        channel.transmit(
            new CommandAPDU(new byte[] {0x00, (byte) 0xC0, 0x00, 0x00, (byte) response.getSW2()}));
    if (response.getSW() != 0x9000) throw new Exception("Failed");
    mProperty2 = response.getData().clone();

    // Read real data
    response =
        channel.transmit(new CommandAPDU(new byte[] {0x00, (byte) 0xB0, 0x00, 0x00, (byte) 0xE6}));
    if (response.getSW() != 0x9000) throw new Exception("Failed to read public data v1");

    byte[] data = response.getData(); // Reference to data
    int nexIndex = 0;
    int endIndex = ARABIC_FULL_NAME_OFFS - 2;

    int startIndex = getNextZero(data, 0);
    int length = data[startIndex + 1];

    int typeId = 0;

    while (startIndex < data.length) {
      if (length == 0) {
        startIndex = getNextZero(data, startIndex);
        length = data[startIndex + 1];
      }

      byte[] tobeExtracted = new byte[length];

      System.arraycopy(data, startIndex + 2, tobeExtracted, 0, length);

      switch (typeId) {
        case 1:
          eid.setIssueDate(Utils.CharArrayToStringDate(Utils.ToCharArray(tobeExtracted)));
          break;
        case 2:
          eid.setExpiryDate(Utils.CharArrayToStringDate(Utils.ToCharArray(tobeExtracted)));
          break;
        case 4:
          eid.setArabicFullName(Utils.CharArrayToUTF8String(Utils.ToCharArray(tobeExtracted)));
          break;
        case 6:
          eid.setFullName(Utils.CharArrayToUTF8String(Utils.ToCharArray(tobeExtracted)));
          break;
        case 7:
          eid.setSex(Utils.CharArrayToUTF8String(Utils.ToCharArray(tobeExtracted)));
          break;
        case 10:
          eid.setNationality(Utils.CharArrayToUTF8String(Utils.ToCharArray(tobeExtracted)));
          break;
        case 11:
          eid.setDateOfBirth(Utils.CharArrayToStringDate(Utils.ToCharArray(tobeExtracted)));
          break;
      }

      if (typeId >= 13) break;

      startIndex = getNextZero(data, startIndex + 2);
      length = data[startIndex + 1];
      typeId = typeId + 1;
    }

    // Read real data
    response =
        channel.transmit(new CommandAPDU(new byte[] {0x00, (byte) 0xB0, 0x00, 0x00, (byte) 0xE6}));
    if (response.getSW() != 0x9000) throw new Exception("Failed to read public data v1");

    data = response.getData(); // Reference to data
    byte a = data[0];

    /*int index = 0;
    String transformed = new String(data, UTF8_CHARSET);*/

    // ---- ISSUE DATE -------------------------------------------------------
    /*{

        String text = HexToChar(data);

        index = getNextZero(data, index);




        endIndex = getNextZero(data, index + 1);

        int length = endIndex - nexIndex;

        byte[] date1 = new byte[length];
        System.arraycopy(data, index+2, date1, 0, length);
        eid.setIssueDate(Utils.CharArrayToStringDate(Utils.ToCharArray(date1)));

        //---- ISSUE DATE -------------------------------------------------------
        System.arraycopy(data, EXPIRY_DATE_OFFS, date1, 0, date1.length);
        eid.setExpiryDate(Utils.CharArrayToStringDate(Utils.ToCharArray(date1)));

        //---- BIRTH DATE -------------------------------------------------------
        System.arraycopy(data, BIRTH_DATE_OFFS, date1, 0, date1.length);
        eid.setDateOfBirth(Utils.CharArrayToStringDate(Utils.ToCharArray(date1)));
    }
    //---- ARABIC NAME -----------------------------------------------------------------
    /*{
        int endIndex = getNextZero(data, ARABIC_FULL_NAME_OFFS);
        int length = endIndex - ARABIC_FULL_NAME_OFFS;

        //byte[] arabic_name = new byte[data[ARABIC_FULL_NAME_OFFS - 1]];
        byte[] arabic_name = new byte[length];
        System.arraycopy(data, ARABIC_FULL_NAME_OFFS, arabic_name, 0, arabic_name.length);
        eid.setArabicFullName(Utils.CharArrayToUTF8String(Utils.ToCharArray(arabic_name)));

        nexIndex = getNextNonZero(data, endIndex + 1);
    }*/
    // ---- ENGLISH NAME
    /*{

        int endIndex = getNextZero(data, nexIndex);
        int length = endIndex - nexIndex;


        byte[] english_name = new byte[length];
        System.arraycopy(data, nexIndex, english_name, 0, english_name.length);
        eid.setFullName(Utils.CharArrayToUTF8String(Utils.ToCharArray(english_name)));
    }*/
    // --- NATIONALITY CODE-------------------------------------------------------------
    /* {
        byte[] nationalityCode = new byte[NATIONALITY_CODE_OFFS - 1];

        //int destIndex = data.length - NATIONALITY_CODE_OFFS - 1;



        System.arraycopy(data, NATIONALITY_CODE_OFFS, nationalityCode, 0, 3);
        String nationality = Utils.CharArrayToUTF8String(Utils.ToCharArray(nationalityCode));
        eid.setNationality(nationality);
    }
    //--- sex ---------------------------------------------------------------------------
    {
        byte[] sex = new byte[]{data[SEX_OFFS]};
        eid.setSex(Utils.CharArrayToUTF8String(Utils.ToCharArray(sex)));
    }
    //-- ID Type ----------------------------------------------------------
    {
        byte[] idType = new byte[ID_TYPE_OFFS-1];
        System.arraycopy(data, ENGLISH_FULL_NAME_OFFS, idType, 0, idType.length);
        eid.setIDType(Utils.CharArrayToUTF8String(Utils.ToCharArray(idType)));
    }*/

    android.util.Log.v("Done with public data", "Public data has been converted successfully");
  }