public static KeyPair func_75891_b() {
   try {
     KeyPairGenerator keypairgenerator = KeyPairGenerator.getInstance("RSA");
     keypairgenerator.initialize(1024);
     return keypairgenerator.generateKeyPair();
   } catch (NoSuchAlgorithmException nosuchalgorithmexception) {
     nosuchalgorithmexception.printStackTrace();
   }
   System.err.println("Key pair generation failed!");
   return null;
 }
 public static PublicKey func_75896_a(byte p_75896_0_[]) {
   try {
     X509EncodedKeySpec x509encodedkeyspec = new X509EncodedKeySpec(p_75896_0_);
     KeyFactory keyfactory = KeyFactory.getInstance("RSA");
     return keyfactory.generatePublic(x509encodedkeyspec);
   } catch (NoSuchAlgorithmException nosuchalgorithmexception) {
     nosuchalgorithmexception.printStackTrace();
   } catch (InvalidKeySpecException invalidkeyspecexception) {
     invalidkeyspecexception.printStackTrace();
   }
   System.err.println("Public key reconstitute failed!");
   return null;
 }
 private static Cipher func_75886_a(int p_75886_0_, String p_75886_1_, Key p_75886_2_) {
   try {
     Cipher cipher = Cipher.getInstance(p_75886_1_);
     cipher.init(p_75886_0_, p_75886_2_);
     return cipher;
   } catch (InvalidKeyException invalidkeyexception) {
     invalidkeyexception.printStackTrace();
   } catch (NoSuchAlgorithmException nosuchalgorithmexception) {
     nosuchalgorithmexception.printStackTrace();
   } catch (NoSuchPaddingException nosuchpaddingexception) {
     nosuchpaddingexception.printStackTrace();
   }
   System.err.println("Cipher creation failed!");
   return null;
 }
  private static byte[] func_75893_a(String p_75893_0_, byte p_75893_1_[][]) {
    try {
      MessageDigest messagedigest = MessageDigest.getInstance(p_75893_0_);
      byte abyte0[][] = p_75893_1_;
      int i = abyte0.length;
      for (int j = 0; j < i; j++) {
        byte abyte1[] = abyte0[j];
        messagedigest.update(abyte1);
      }

      return messagedigest.digest();
    } catch (NoSuchAlgorithmException nosuchalgorithmexception) {
      nosuchalgorithmexception.printStackTrace();
    }
    return null;
  }
 public static byte[] encryptData(Key key, byte[] toEncrypt) {
   try {
     Cipher cipher = Cipher.getInstance(key.getAlgorithm());
     cipher.init(Cipher.ENCRYPT_MODE, key);
     return cipher.doFinal(toEncrypt);
   } catch (NoSuchAlgorithmException e) {
     e.printStackTrace();
   } catch (NoSuchPaddingException e) {
     e.printStackTrace();
   } catch (InvalidKeyException e) {
     e.printStackTrace();
   } catch (BadPaddingException e) {
     e.printStackTrace();
   } catch (IllegalBlockSizeException e) {
     e.printStackTrace();
   }
   return new byte[0];
 }
  public boolean delete(String filename, UserToken token) {
    try {
      String remotePath;
      if (filename.charAt(0) == '/') {
        remotePath = filename.substring(1);
      } else {
        remotePath = filename;
      }
      Envelope env = new Envelope("DELETEF"); // Success
      env.addObject(remotePath);
      env.addObject(token);
      String concat =
          remotePath
              + token.toString()
              + "DELETEF"
              + nonce; // concatinates all of the objects in envelope
      byte[] hasharray = concat.getBytes(); // turn the concat into a byte array
      Mac mac = Mac.getInstance("HmacSHA1");
      mac.init(HMACkey);
      mac.update(hasharray);
      String stringhash =
          new String(mac.doFinal(), "UTF8"); // turn the hash into a string for easy comparision!
      env.addObject(stringhash);
      env.addObject(nonce);
      nonce++;

      byte[] envBytes = Envelope.toByteArray(env);

      // Encrypt envelope w/ AES
      Cipher cipher = Cipher.getInstance("AES");
      cipher.init(Cipher.ENCRYPT_MODE, AESkey);
      byte[] cipherBytes = cipher.doFinal(envBytes);

      output.writeObject(cipherBytes);

      byte[] responseCipherBytes = (byte[]) input.readObject();

      // Decrypt response
      cipher.init(Cipher.DECRYPT_MODE, AESkey);
      byte[] responseBytes = cipher.doFinal(responseCipherBytes);

      env = Envelope.getEnvelopefromBytes(responseBytes);
      System.out.println(env.getMessage());
      if ((Integer) env.getObjContents().get(1) == nonce) {
        String hash = (String) env.getObjContents().get(0);
        concat = env.getMessage() + nonce; // reconstructs the hash
        hasharray = concat.getBytes();
        mac = Mac.getInstance("HmacSHA1");
        File HASHfile = new File("FHASHKey.bin");
        FileInputStream fis = new FileInputStream(HASHfile);
        ObjectInputStream ois = new ObjectInputStream(fis);
        Key HMACkey = (Key) ois.readObject();
        mac.init(HMACkey);
        mac.update(hasharray);
        String newhash = new String(mac.doFinal(), "UTF8");
        nonce++;

        if (hash.equals(newhash) != true) // check hashes for equality
        {
          System.out.println("HASH EQUALITY FAIL");
          return false;
        }

        if (env.getMessage().compareTo("OK") == 0) {
          System.out.printf("File %s deleted successfully\n", filename);
        } else {
          System.out.printf("Error deleting file %s (%s)\n", filename, env.getMessage());
          return false;
        }
      }
    } catch (IllegalBlockSizeException ex) {
      ex.printStackTrace(System.err);
    } catch (BadPaddingException ex) {
      ex.printStackTrace(System.err);
    } catch (InvalidKeyException ex) {
      ex.printStackTrace(System.err);
    } catch (NoSuchAlgorithmException ex) {
      ex.printStackTrace(System.err);
    } catch (NoSuchPaddingException ex) {
      ex.printStackTrace(System.err);
    } catch (IOException e1) {
      e1.printStackTrace(System.err);
    } catch (ClassNotFoundException e1) {
      e1.printStackTrace(System.err);
    }

    return true;
  }
  public Object transformMessage(MuleMessage message, String outputEncoding)
      throws TransformerException {

    Arrays.fill(ivBytes, (byte) 0x00);
    iv = new IvParameterSpec(ivBytes);

    Object derivedKey = message.getInvocationProperty("derivedKey");
    if (null == derivedKey) {
      keyValue = Base64.decodeBase64(DEFAULT_KEY.getBytes());
    } else {
      keyValue = Base64.decodeBase64(derivedKey.toString().getBytes());
    }
    SecretKeySpec skeySpec = new SecretKeySpec(keyValue, "AES");

    Cipher cipher = null;
    try {
      cipher = Cipher.getInstance(ALGO);
    } catch (NoSuchAlgorithmException e1) {
      e1.printStackTrace();
    } catch (NoSuchPaddingException e1) {
      e1.printStackTrace();
    }

    try {
      cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
    } catch (InvalidKeyException | InvalidAlgorithmParameterException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }

    byte[] original = null;
    try {
      // Object queryParm1 = message.getPayload().toString());	//"2zU3YSkvbamjrlE7WgBaKA==");
      // Object queryParm1 = message.getInvocationProperty("1");

      // HashMap queryParms = (HashMap)message.getInboundProperty("http.query.params");
      // Object queryParm1 = queryParms.get("1");

      Object queryParm1 = message.getInvocationProperty("encryptedPatientId");

      if (queryParm1 != null) {
        byte[] encString = Base64.decodeBase64(queryParm1.toString().getBytes());
        original = cipher.doFinal(encString);

        String clearText = "";
        try {
          clearText = new String(original, UNICODE_FORMAT).trim();
          // message.setInvocationProperty("patientId", clearText);
          message.setOutboundProperty("patientId", clearText);

        } catch (UnsupportedEncodingException e1) {
          // TODO Auto-generated catch block
          e1.printStackTrace();
        }
      }

    } catch (IllegalBlockSizeException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    } catch (BadPaddingException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }

    return message;
  }