예제 #1
0
 public byte[] xtsBlockDecrypt(byte[] cipher, int j) {
   byte[] cc = xor(cipher, tTable[j]);
   aes.setKey(key1);
   byte[] pp = aes.decrypt(cc);
   byte[] pj = xor(pp, tTable[j]);
   return pj;
 }
 public static String decrypt(
     final String text, final String password, final byte[] salt, final byte[] iv) {
   final byte[] encryptedData = CryptoHelper.base64Decode(text);
   final byte[] data =
       AES.decrypt(
           encryptedData, password, salt, iv, AES.KEY_SIZE_DEFAULT, AES.ITERATION_COUNT_DEFAULT);
   return CryptoHelper.getString(data);
 }
 public static byte[] decrypt(
     final byte[] data,
     final String password,
     final byte[] salt,
     final byte[] iv,
     final int keySize) {
   return AES.decrypt(data, password, salt, iv, keySize, AES.ITERATION_COUNT_DEFAULT);
 }
 public static byte[] decrypt(final byte[] data, final String password) {
   return AES.decrypt(
       data,
       password,
       AES.getSimpleSalt(),
       AES.getSimpleIV(),
       AES.KEY_SIZE_DEFAULT,
       AES.ITERATION_COUNT_DEFAULT);
 }
 public void run() {
   while (true) {
     try {
       String msg = streamIn.readUTF();
       client.handle(AES.decrypt(msg, enc_key));
     } catch (IOException ioe) {
       JOptionPane.showMessageDialog(
           null, ioe.getMessage(), "Listening Error!", JOptionPane.ERROR_MESSAGE);
       client.stop();
     } catch (Exception ex) {
       JOptionPane.showMessageDialog(null, ex.getMessage(), "Error!", JOptionPane.ERROR_MESSAGE);
       client.stop();
     }
   }
 }
예제 #6
0
  @Test
  public void test()
      throws NoSuchAlgorithmException, InvalidKeyException, NoSuchPaddingException,
          IllegalBlockSizeException, BadPaddingException, InvalidKeySpecException,
          UnsupportedEncodingException, InvalidAlgorithmParameterException {
    String data1 = "阿迪是发送发达撒地方";
    String key = "ABCDABCDABCDABCD12";

    System.out.println("原数据为:" + data1);
    System.out.println("密匙为:" + key);

    String data2 = AES.encrypt(key, data1, AES.ALGORITHM_ECB);
    System.out.println("加密后数据为:" + data2);

    String data3 = AES.decrypt(key, data2, AES.ALGORITHM_ECB);
    System.out.println("解密后数据为:" + data3);
    Assert.assertEquals(data1, data3);
  }
예제 #7
0
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == j1) {
      System.exit(0);
    }
    if (e.getSource() == j2) {

      try {
        InetAddress ia = InetAddress.getLocalHost();
        String ip = ia.getHostAddress();

        String name = JOptionPane.showInputDialog("Enter Your name");
        String owner = JOptionPane.showInputDialog("Enter Owner Name");

        String[] csname = {"Select Cloud Server", "CS1", "CS2", "CS3"};

        String ip1 = JOptionPane.showInputDialog("Enter cloud Ip address");
        String cloudname =
            (String)
                JOptionPane.showInputDialog(
                    null,
                    "Select Cloud Server",
                    "CloudName",
                    JOptionPane.QUESTION_MESSAGE,
                    null,
                    csname,
                    csname[0]);

        if (cloudname.equalsIgnoreCase("CS1")) {
          Socket sc = new Socket(ip1, 302);
          DataOutputStream dout = new DataOutputStream(sc.getOutputStream());
          dout.writeUTF("check");
          dout.writeUTF(name);
          dout.writeUTF(owner);
          dout.writeUTF(ip);

          DataInputStream din = new DataInputStream(sc.getInputStream());
          String msg = din.readUTF();
          if (msg.equalsIgnoreCase("success")) {
            String filename1 = JOptionPane.showInputDialog("Enter the filename");
            String sec = JOptionPane.showInputDialog("Enter secretkey");

            Socket sc1 = new Socket(ip1, 302);
            DataOutputStream dout1 = new DataOutputStream(sc1.getOutputStream());
            dout1.writeUTF("download");
            dout1.writeUTF(name);
            dout1.writeUTF(owner);
            dout1.writeUTF(filename1);
            dout1.writeUTF(sec);
            dout1.writeUTF(ip);

            DataInputStream oin = new DataInputStream(sc1.getInputStream());
            String msg1 = oin.readUTF();
            System.out.println(msg1);

            if (msg1.equalsIgnoreCase("success")) {
              System.out.println("success");
              AES a3 = new AES();
              String data1 = oin.readUTF();
              String data = a3.decrypt(data1, keyword);
              tf.setText(data);
              PrintStream p = new PrintStream("user/" + filename1);
              p.write(data.getBytes());

              JOptionPane.showMessageDialog(null, "FileDownloaded Successfully");
              int i =
                  JOptionPane.showConfirmDialog(null, "Do you want to open file Downloaded Folder");
              if (i == 0) {
                File f = new File("user");
                Desktop desktop = Desktop.getDesktop();
                desktop.open(f);

              } else if (i == 1) {

              }
            } else if (msg1.equalsIgnoreCase("failure")) {
              JOptionPane.showMessageDialog(
                  null, "you are trying to attack the file, You are Automatically blocked");
            } else if (msg1.equalsIgnoreCase("not")) {
              JOptionPane.showMessageDialog(null, "File Not Found in Cloud Server");
            }

          } else if (msg.equalsIgnoreCase("block")) {
            JOptionPane.showMessageDialog(
                null, "You are Curently blocked ..!!!! \n To access Contact Cloud Server");
          } else if (msg.equalsIgnoreCase("unblock")) {
            JOptionPane.showMessageDialog(null, "Remote user not Registered in Cloud Server");
          }

        } else if (cloudname.equalsIgnoreCase("CS2")) {
          Socket sc = new Socket(ip1, 352);
          DataOutputStream dout = new DataOutputStream(sc.getOutputStream());
          dout.writeUTF("check");
          dout.writeUTF(name);
          dout.writeUTF(owner);
          dout.writeUTF(ip);

          DataInputStream din = new DataInputStream(sc.getInputStream());
          String msg = din.readUTF();
          if (msg.equalsIgnoreCase("success")) {
            String filename1 = JOptionPane.showInputDialog("Enter the filename");
            String sec = JOptionPane.showInputDialog("Enter secretkey");
            // String ip1=JOptionPane.showInputDialog("Enter cloud Ip address");

            Socket sc1 = new Socket(ip1, 352);
            DataOutputStream dout1 = new DataOutputStream(sc1.getOutputStream());
            dout1.writeUTF("download");
            dout1.writeUTF(name);
            dout1.writeUTF(owner);
            dout1.writeUTF(filename1);
            dout1.writeUTF(sec);
            dout1.writeUTF(ip);

            DataInputStream oin = new DataInputStream(sc1.getInputStream());
            String msg1 = oin.readUTF();
            System.out.println(msg1);

            if (msg1.equalsIgnoreCase("success")) {
              System.out.println("success");
              AES a3 = new AES();
              String data1 = oin.readUTF();
              String data = a3.decrypt(data1, keyword);
              tf.setText(data);
              PrintStream p = new PrintStream("user/" + filename1);
              p.write(data.getBytes());

              JOptionPane.showMessageDialog(null, "FileDownloaded Successfully");
              int i =
                  JOptionPane.showConfirmDialog(null, "Do you want to open file Downloaded Folder");
              if (i == 0) {
                File f = new File("user");
                Desktop desktop = Desktop.getDesktop();
                desktop.open(f);

              } else if (i == 1) {

              }
            } else if (msg1.equalsIgnoreCase("failure")) {
              JOptionPane.showMessageDialog(
                  null, "you are trying to attack the file, You are Automatically blocked");
            } else if (msg1.equalsIgnoreCase("not")) {
              JOptionPane.showMessageDialog(null, "File Not Found in Cloud Server");
            }

          } else if (msg.equalsIgnoreCase("block")) {
            JOptionPane.showMessageDialog(
                null, "You are Curently blocked ..!!!! \n To access Contact Cloud Server");
          } else if (msg.equalsIgnoreCase("unblock")) {
            JOptionPane.showMessageDialog(null, "Remote user not Registered in Cloud Server");
          }

        } else if (cloudname.equalsIgnoreCase("CS3")) {
          Socket sc = new Socket(ip1, 362);
          DataOutputStream dout = new DataOutputStream(sc.getOutputStream());
          dout.writeUTF("check");
          dout.writeUTF(name);
          dout.writeUTF(owner);
          dout.writeUTF(ip);

          DataInputStream din = new DataInputStream(sc.getInputStream());
          String msg = din.readUTF();
          if (msg.equalsIgnoreCase("success")) {
            String filename1 = JOptionPane.showInputDialog("Enter the filename");
            String sec = JOptionPane.showInputDialog("Enter secretkey");
            // String ip1=JOptionPane.showInputDialog("Enter cloud Ip address");

            Socket sc1 = new Socket(ip1, 362);
            DataOutputStream dout1 = new DataOutputStream(sc1.getOutputStream());
            dout1.writeUTF("download");
            dout1.writeUTF(name);
            dout1.writeUTF(owner);
            dout1.writeUTF(filename1);
            dout1.writeUTF(sec);
            dout1.writeUTF(ip);

            DataInputStream oin = new DataInputStream(sc1.getInputStream());
            String msg1 = oin.readUTF();
            System.out.println(msg1);

            if (msg1.equalsIgnoreCase("success")) {
              System.out.println("success");
              AES a3 = new AES();
              String data1 = oin.readUTF();
              String data = a3.decrypt(data1, keyword);
              tf.setText(data);
              PrintStream p = new PrintStream("user/" + filename1);
              p.write(data.getBytes());

              JOptionPane.showMessageDialog(null, "FileDownloaded Successfully");
              int i =
                  JOptionPane.showConfirmDialog(null, "Do you want to open file Downloaded Folder");
              if (i == 0) {
                File f = new File("user");
                Desktop desktop = Desktop.getDesktop();
                desktop.open(f);

              } else if (i == 1) {

              }
            } else if (msg1.equalsIgnoreCase("failure")) {
              JOptionPane.showMessageDialog(
                  null, "you are trying to attack the file, You are Automatically blocked");
            } else if (msg1.equalsIgnoreCase("not")) {
              JOptionPane.showMessageDialog(null, "File Not Found in Cloud Server");
            }

          } else if (msg.equalsIgnoreCase("block")) {
            JOptionPane.showMessageDialog(
                null, "You are Curently blocked ..!!!! \n To access Contact Cloud Server");
          } else if (msg.equalsIgnoreCase("unblock")) {
            JOptionPane.showMessageDialog(null, "Remote user not Registered in Cloud Server");
          }
        }

      } catch (Exception e1) {
        e1.printStackTrace();
      }
    }

    if (e.getSource() == j3) {

      try {

        String owner = JOptionPane.showInputDialog("Enter Owner Name");
        String fname = JOptionPane.showInputDialog("Enter File Name");
        String[] csname = {"Select Cloud Server", "CS1", "CS2", "CS3"};

        String cloudname =
            (String)
                JOptionPane.showInputDialog(
                    null,
                    "Select Cloud Server",
                    "CloudName",
                    JOptionPane.QUESTION_MESSAGE,
                    null,
                    csname,
                    csname[0]);
        String ip = JOptionPane.showInputDialog(null, "Enter Cloud Server IP Address");

        if (cloudname.equalsIgnoreCase("CS1")) {
          Socket sc = new Socket(ip, 1717);
          DataOutputStream dout = new DataOutputStream(sc.getOutputStream());

          dout.writeUTF(owner);
          dout.writeUTF(fname);
          dout.writeUTF(cloudname);

          DataInputStream din = new DataInputStream(sc.getInputStream());
          String msg = din.readUTF();
          if (msg.equalsIgnoreCase("success")) {
            JOptionPane.showMessageDialog(null, "Note Down Your Secrete Key :" + din.readUTF());

          } else if (msg.equalsIgnoreCase("failure")) {
            JOptionPane.showMessageDialog(null, "File not found in cloud server");
          }

        } else if (cloudname.equalsIgnoreCase("CS2")) {
          Socket sc = new Socket(ip, 1717);
          DataOutputStream dout = new DataOutputStream(sc.getOutputStream());

          dout.writeUTF(owner);
          dout.writeUTF(fname);
          dout.writeUTF(cloudname);

          DataInputStream din = new DataInputStream(sc.getInputStream());
          String msg = din.readUTF();
          if (msg.equalsIgnoreCase("success")) {
            JOptionPane.showMessageDialog(null, "Note Down Your Secrete Key :" + din.readUTF());
          } else if (msg.equalsIgnoreCase("failure")) {
            JOptionPane.showMessageDialog(
                null, "you are trying to attack the file, You are Automatically blocked");
          }

        } else if (cloudname.equalsIgnoreCase("CS3")) {
          Socket sc = new Socket(ip, 1717);
          DataOutputStream dout = new DataOutputStream(sc.getOutputStream());

          dout.writeUTF(owner);
          dout.writeUTF(fname);
          dout.writeUTF(cloudname);

          DataInputStream din = new DataInputStream(sc.getInputStream());
          String msg = din.readUTF();
          if (msg.equalsIgnoreCase("success")) {
            JOptionPane.showMessageDialog(null, "Note Down Your Secrete Key :" + din.readUTF());
          } else if (msg.equalsIgnoreCase("failure")) {
            JOptionPane.showMessageDialog(
                null, "you are trying to attack the file, You are Automatically blocked");
          }
        }

      } catch (Exception e1) {
        e1.printStackTrace();
      }
    }
  }
 public static String decrypt(final String text, final String password, final byte[] salt) {
   return AES.decrypt(text, password, salt, AES.getSimpleIV());
 }
 public static String decrypt(final String text, final String password) {
   return AES.decrypt(text, password, AES.getSimpleSalt(), AES.getSimpleIV());
 }
 public static byte[] decrypt(
     final byte[] data, final String password, final byte[] salt, final byte[] iv) {
   return AES.decrypt(
       data, password, salt, iv, AES.KEY_SIZE_DEFAULT, AES.ITERATION_COUNT_DEFAULT);
 }