Esempio n. 1
0
  public String ReadFromSmartCard(byte file, byte id, int lent) {
    String info = "none";
    try {
      if (this.terminal != null && this.terminal.isCardPresent()) {
        if (this.SelectFileFromSmartCard(file, id)) {
          CardChannel channel = card1.getBasicChannel();
          byte[] val = infoTOwrite.getBytes();
          // new CommandAPDU(0x80,0xD2,0x01,0x00,val)
          r = channel.transmit(new CommandAPDU(0x80, 0xB2, 0x01, 0x00, lent));
          // channel.transmit((Buffer)apdu, apdu);
          System.out.println("The response2 to string is: " + r.toString());
          System.out.println("The response2 to Sting() DATA ISSS: " + r.getData().toString());
          byte dat[] = r.getData();
          System.out.println("The response2 DATA ISSS: " + r.getData());
          System.out.println(
              "The RESPONSE2 FOR GETDATA() IS "
                  + new Concatenation().ConvertByteToString(r.getData()));
          System.out.println(
              "The RESPONSE2 FOR GETBYTE() IS "
                  + new Concatenation().ConvertByteToString(r.getBytes()));
          // Integer.toHexString(javaCard.getStatusWords()).toUpperCase()
          System.out.println("The SW1 is: " + Integer.toHexString(r.getSW1()));
          System.out.println("The SW2 is: " + Integer.toHexString(r.getSW2()));
          System.out.println("The tHE WhoLE SW is: " + Integer.toHexString(r.getSW()));
          // r = channel.transmit(new CommandAPDU(new
          // byte[]{CLASS,(byte)0xA4,(byte)0x00,(byte)0x00,(byte)0x02,0,(byte)0x02,0}));
          if (Integer.toHexString(r.getSW()).equals("9000")
              || Integer.toHexString(r.getSW()).equals("9102")) {
            info = new Concatenation().ConvertByteToString(r.getData());

            System.out.println("OPERATION ON THE FILE WAS SUCCESSFUL");
          } else {
            System.out.println("OPERATION ON THE FILE WAS NOT SUCCESSFUL");
          }
        } else {
          System.out.println("FILE selection WAS nOt SUCCESSFUL:Thus cannot read from it");
        }
      } else {
        JOptionPane.showMessageDialog(
            null,
            "Card is absent.Please insert your smartCard\n to connnect it in 5 secs\nWaiting...");
      }

    } catch (CardException ce) {
      System.out.println("The Error cause is:" + ce.getMessage());
      ce.printStackTrace();
    } finally {
      try {
        this.card1.disconnect(true);
      } catch (CardException ce) {
        System.out.println("COULDN'T DISCONNECT CARD is:" + ce.getMessage());
        ce.printStackTrace();
      }
    }
    return info.trim();
  }
Esempio n. 2
0
  public boolean IsSmartCardFormated_Personalized() {
    byte id = (byte) 0x04;
    byte userregfileid = (byte) 0x02;

    Boolean IsWriiten = false;
    try {
      if (this.terminal != null && this.terminal.isCardPresent()) {
        if (this.SelectFileFromSmartCard(DATA, userregfileid)) {
          IsWriiten = true;
          // JOptionPane.showMessageDialog(null,"pls your card has  been formatted.");
        } else {
          System.out.println("pls your card has not been formatted");
          JOptionPane.showMessageDialog(null, "Please your card has not been formatted.");
        }
      } else {
        JOptionPane.showMessageDialog(
            null,
            "Card is absent.Please insert your smartCard\n to connnect it in 5 secs\nWaiting...");
      }

    } catch (CardException ce) {
      System.out.println("The Error cause is:" + ce.getMessage());
      ce.printStackTrace();
    }

    return IsWriiten;
  }
Esempio n. 3
0
 public boolean disconnectSmartCard() {
   boolean Isdisconnect = false;
   try {
     this.card1.disconnect(true);
     Isdisconnect = true;
   } catch (CardException ce) {
     System.out.println("COULDN'T DISCONNECT CARD is:" + ce.getMessage());
     ce.printStackTrace();
   }
   return Isdisconnect;
 }
Esempio n. 4
0
  public boolean InitializePersonalizationFILE() {
    byte id = (byte) 0x02;

    Boolean IsWriiten = false;
    try {
      if (this.terminal != null && this.terminal.isCardPresent()) {
        if (this.SubmittIC() && this.SelectFileFromSmartCard(PERSONALIZE_FILE, id)) {
          CardChannel channel = card1.getBasicChannel();

          // byte USERid=(byte)0x11;
          // new CommandAPDU(0x80,0xD2,0x01,0x00,val)
          // 80 D2 00 00 06 05 03 00 00 F0 02
          // 0x80,0xD2,0x00,0x00,0x06,0x05,0x03,0x00,0x00,0xF0,0x02
          // r= channel.transmit(new CommandAPDU(0x80,0xD2,0x01,0x00,val));80 D2 00 00 04 00 00 03
          // 00
          byte[] SelectFilecomAPDUBytes =
              new byte[] {CLASS, writeINS2, 0x00, 0x00, 0x04, 0x00, 0x00, 0x04, 0x00};
          r = channel.transmit(new CommandAPDU(SelectFilecomAPDUBytes));
          // channel.transmit((Buffer)apdu, apdu);
          System.out.println("The response2 to string is: " + r.toString());
          System.out.println("The response2 to Sting() DATA ISSS: " + r.getData().toString());
          byte dat[] = r.getData();

          // Integer.toHexString(javaCard.getStatusWords()).toUpperCase()
          System.out.println("The SW1 is: " + Integer.toHexString(r.getSW1()));
          System.out.println("The SW2 is: " + Integer.toHexString(r.getSW2()));
          System.out.println("The tHE WhoLE SW is: " + Integer.toHexString(r.getSW()));
          // r = channel.transmit(new CommandAPDU(new
          // byte[]{CLASS,(byte)0xA4,(byte)0x00,(byte)0x00,(byte)0x02,0,(byte)0x02,0}));
          if (Integer.toHexString(r.getSW()).equals("9000")
              || Integer.toHexString(r.getSW()).equals("9102")) {
            IsWriiten = true;

            System.out.println(" WRITTEN OPERATION ON THE FILE WAS SUCCESSFUL");
          } else {
            IsWriiten = false;
            System.out.println(" WRITTEN OPERATION ON THE FILE WAS NOT SUCCESSFUL");
          }
        } else {
          System.out.println("FILE selection WAS nOt SUCCESSFUL:Thus cannot write to it");
        }
      } else {
        JOptionPane.showMessageDialog(
            null,
            "Card is absent.Please insert your smartCard\n to connnect it in 5 secs\nWaiting...");
      }

    } catch (CardException ce) {
      System.out.println("The Error cause is:" + ce.getMessage());
      ce.printStackTrace();
    }

    return IsWriiten;
  }
Esempio n. 5
0
  public boolean Format_PersonalizeSmartCard() {
    byte id = (byte) 0x04;
    byte userregfileid = (byte) 0x02;

    Boolean IsWriiten = false;
    try {
      if (this.terminal != null && this.terminal.isCardPresent()) {
        if (this.SelectFileFromSmartCard(DATA, userregfileid)) {
          IsWriiten = false;
          JOptionPane.showMessageDialog(
              null,
              "Please this card has INITIALLY been formatted .Please insert a new one.\nThank you",
              "ALREADY USED/FORMMATTED",
              2);
        } else if (this.InitializePersonalizationFILE() && this.PersonalizeCard()) {
          System.out.println("Please your card has not been formatted");
          // this.WriteToSmartCard(DATA, userregfileid,"AFAMO");
          IsWriiten = true;
          JOptionPane.showMessageDialog(
              null, "Congratulations!!!\n Your smartcard IS NOW  formatted.");
        } else {
          IsWriiten = false;
          System.out.println("Please your card has not been formatted");
          JOptionPane.showMessageDialog(
              null,
              "Please your card can neither be formatted nor personalized\n.Please make sure that it is ACS ACOS3 SmartCard\n And that the card is not damaged");
          // return;
        }
      } else {
        JOptionPane.showMessageDialog(
            null,
            "Card is absent.Please insert your smartCard\n to connnect it in 5 secs\nWaiting...");
      }

    } catch (CardException ce) {
      System.out.println("The Error cause is:" + ce.getMessage());
      ce.printStackTrace();
    }

    return IsWriiten;
  }
Esempio n. 6
0
  public boolean WriteToSmartCard(byte file, byte id, String data) {
    Boolean IsWriiten = false;
    String code = "donsimon999_@afamokonkwo#healing";
    byte[] val1 = code.getBytes();
    try {
      if (this.terminal != null && this.terminal.isCardPresent()) {
        CardChannel channel = card1.getBasicChannel();
        if (this.SubmittIC() && this.SelectFileFromSmartCard(file, id)) {

          byte[] val = data.getBytes();

          int lent = data.length();
          byte id1 = (byte) 0x09;
          // byte data_lent=lent.
          // new CommandAPDU(0x80,0xD2,0x01,0x00,val)
          r = channel.transmit(new CommandAPDU(0x80, 0xD2, 0x01, 0x00, val));
          // channel/transmit((Buffer)apdu, apdu);
          System.out.println("The response2 to string is: " + r.toString());
          System.out.println("The response2 to Sting() DATA ISSS: " + r.getData().toString());
          byte dat[] = r.getData();
          System.out.println("The response2 DATA ISSS: " + r.getData());
          System.out.println(
              "The RESPONSE2 FOR GETDATA() IS "
                  + new Concatenation().ConvertByteToString(r.getData()));
          System.out.println(
              "The RESPONSE2 FOR GETBYTE() IS "
                  + new Concatenation().ConvertByteToString(r.getBytes()));
          // Integer.toHexString(javaCard.getStatusWords()).toUpperCase()
          System.out.println("The SW1 is: " + Integer.toHexString(r.getSW1()));
          System.out.println("The SW2 is: " + Integer.toHexString(r.getSW2()));
          System.out.println("The tHE WhoLE SW is: " + Integer.toHexString(r.getSW()));
          // r = channel.transmit(new CommandAPDU(new
          // byte[]{CLASS,(byte)0xA4,(byte)0x00,(byte)0x00,(byte)0x02,0,(byte)0x02,0}));
          if (Integer.toHexString(r.getSW()).equals("9000")
              || Integer.toHexString(r.getSW()).equals("9102")) {
            // r= channel.transmit(new CommandAPDU(0x80,0xD2,0x01,0x00,val));

            System.out.println("OPERATION ON THE FILE1 WAS SUCCESSFUL");
            if (this.SubmittIC() && this.SelectFileFromSmartCard(DATA1, id1)) {
              // CardChannel channel = card1.getBasicChannel();
              // byte[] val= data.getBytes();

              // int lent=data.length();
              // byte data_lent=lent.
              // new CommandAPDU(0x80,0xD2,0x01,0x00,val)
              r = channel.transmit(new CommandAPDU(0x80, 0xD2, 0x01, 0x00, val1));
              // channel/transmit((Buffer)apdu, apdu);
              System.out.println("The response2 to string is: " + r.toString());
              System.out.println("The response2 to Sting() DATA ISSS: " + r.getData().toString());
              // byte dat[]=r.getData();
              System.out.println("The response2 DATA ISSS: " + r.getData());
              System.out.println(
                  "The RESPONSE2 FOR GETDATA() IS "
                      + new Concatenation().ConvertByteToString(r.getData()));
              System.out.println(
                  "The RESPONSE2 FOR GETBYTE() IS "
                      + new Concatenation().ConvertByteToString(r.getBytes()));
              // Integer.toHexString(javaCard.getStatusWords()).toUpperCase()
              System.out.println("The SW1 is: " + Integer.toHexString(r.getSW1()));
              System.out.println("The SW2 is: " + Integer.toHexString(r.getSW2()));
              System.out.println("The tHE WhoLE SW is: " + Integer.toHexString(r.getSW()));
              // r = channel.transmit(new CommandAPDU(new
              // byte[]{CLASS,(byte)0xA4,(byte)0x00,(byte)0x00,(byte)0x02,0,(byte)0x02,0}));
              if (Integer.toHexString(r.getSW()).equals("9000")
                  || Integer.toHexString(r.getSW()).equals("9102")) {
                // r= channel.transmit(new CommandAPDU(0x80,0xD2,0x01,0x00,val));
                IsWriiten = true;

                System.out.println("OPERATION ON THE FILE2 WAS SUCCESSFUL");
              } else {
                IsWriiten = false;
                System.out.println("OPERATION ON THE FILE2 WAS NOT SUCCESSFUL");
              }
            } else {
              System.out.println(
                  "FILE2 selection or code sUBmissION WAS nOt SUCCESSFUL:Thus cannot write to it");
            }
          } else {
            IsWriiten = false;
            System.out.println("OPERATION ON THE FILE1 WAS NOT SUCCESSFUL");
          }
        } else {
          System.out.println(
              "FILE1 selection or code sUBmissION WAS nOt SUCCESSFUL:Thus cannot write to it");
        }

      } else {
        JOptionPane.showMessageDialog(
            null,
            "Card is absent.Please insert your smartCard\n to connnect it in 5 secs\nWaiting...");
      }

    } catch (CardException ce) {
      System.out.println("The Error cause is:" + ce.getMessage());
      ce.printStackTrace();
    } finally {
      try {
        this.card1.disconnect(true);
      } catch (CardException ce) {
        System.out.println("COULDN'T DISCONNECT CARD is:" + ce.getMessage());
        ce.printStackTrace();
      }
    }

    return IsWriiten;
  }
Esempio n. 7
0
  public boolean SubmittIC() {
    byte id = (byte) 0x04;
    Boolean IsUBMITTED = false;
    String data_to_write = byteArrayToHexString(infoTOwrite.getBytes());

    // System.out.println("The Hex String to write is: "+data_to_write);
    // WRITEcommand=WRITEcommand.concat(data_to_write);
    // System.out.println("The Hex command to write is: "+WRITEcommand);
    // byte val []= hexStringToByteArray(data_to_write);
    // System.out.println("The FINAL COMMAND TO WRITE ISSSS: "+htos(val));

    try {
      if (this.terminal != null && this.terminal.isCardPresent()) {
        if (this.SelectFileFromSmartCard(USER_FILE, id)) {
          CardChannel channel = card1.getBasicChannel();

          byte USERFiLE = (byte) 0xF0;
          byte USERid = (byte) 0x02;

          // byte []val=hexStringToByteArray("ACOSTEST");

          // System.out.println("The submitted code in byte IS: "+new
          // Concatenation().ConvertByteToString(val));
          // new CommandAPDU(0x80,0xD2,0x01,0x00,val)
          // 80 D2 00 00 06 05 03 00 00 F0 02
          // 0x80,0xD2,0x00,0x00,0x06,0x05,0x03,0x00,0x00,0xF0,0x02
          // r= channel.transmit(new CommandAPDU(0x80,0xD2,0x01,0x00,val));
          // byte [ ] SelectFilecomAPDUBytes = new byte []{CLASS,writeINS2, 0x00, 0x00,
          // 0x06,0x05,0x03,0x00,0x02,USERFiLE,USERid};
          byte[] CODESUBcomAPDUBytes =
              new byte[] {
                CLASS, 0x20, 0x07, 0x00, 0x08, 0x41, 0x43, 0x4F, 0x53, 0x54, 0x45, 0x53, 0x54
              };
          // 41 43 4f 53 54 45 53 54
          // new CommandAPDU(CLASS,0x20,0x07,0x00,0x08,val
          r = channel.transmit(new CommandAPDU(CODESUBcomAPDUBytes));
          // channel.transmit((Buffer)apdu, apdu);
          System.out.println("The response2 to string is: " + r.toString());
          System.out.println("The response2 to Sting() DATA ISSS: " + r.getData().toString());
          byte dat[] = r.getData();
          System.out.println("The response2 DATA ISSS: " + r.getData());
          System.out.println(
              "The RESPONSE2 FOR GETDATA() IS "
                  + new Concatenation().ConvertByteToString(r.getData()));
          System.out.println(
              "The RESPONSE2 FOR GETBYTE() IS "
                  + new Concatenation().ConvertByteToString(r.getBytes()));
          // Integer.toHexString(javaCard.getStatusWords()).toUpperCase()
          System.out.println("The SW1 is: " + Integer.toHexString(r.getSW1()));
          System.out.println("The SW2 is: " + Integer.toHexString(r.getSW2()));
          System.out.println("The tHE WhoLE SW is: " + Integer.toHexString(r.getSW()));
          // r = channel.transmit(new CommandAPDU(new
          // byte[]{CLASS,(byte)0xA4,(byte)0x00,(byte)0x00,(byte)0x02,0,(byte)0x02,0}));
          if (Integer.toHexString(r.getSW()).equals("9000")
              || Integer.toHexString(r.getSW()).equals("9102")) {
            IsUBMITTED = true;

            System.out.println(" CODE SUBMISSION WAS SUCCESSFUL");
          } else {
            IsUBMITTED = false;
            System.out.println(" CODE SUBMISSION WAS NOT SUCCESSFUL");
          }
        } else {
          System.out.println("FILE selection WAS nOt SUCCESSFUL:Thus cannot write to it");
        }
      } else {
        JOptionPane.showMessageDialog(
            null,
            "Card is absent.Please insert your smartCard\n to connnect it in 5 secs\nWaiting...");
      }

    } catch (CardException ce) {
      System.out.println("The Error cause is:" + ce.getMessage());
      ce.printStackTrace();
    }

    return IsUBMITTED;
  }