Ejemplo n.º 1
0
 /**
  * Get parameters
  *
  * @param hit String
  * @return HashMap
  */
 static LinkedHashMap<String, String> getParameters(String hit) {
   LinkedHashMap<String, String> map = new LinkedHashMap<>();
   try {
     URL url = new URL(hit);
     map.put("ssl", url.getProtocol().equals("http") ? "Off" : "On");
     map.put("log", url.getHost());
     String[] queryComponents = url.getQuery().split("&");
     for (String queryComponent : queryComponents) {
       String[] elem = queryComponent.split("=");
       if (elem.length > 1) {
         elem[1] = Tool.percentDecode(elem[1]);
         if (Tool.parseJSON(elem[1]) instanceof JSONObject) {
           JSONObject json = (JSONObject) Tool.parseJSON(elem[1]);
           if (json != null && elem[0].equals(Hit.HitParam.JSON.stringValue())) {
             map.put(elem[0], json.toString(3));
           } else {
             map.put(elem[0], elem[1]);
           }
         } else {
           map.put(elem[0], elem[1]);
         }
       } else {
         map.put(elem[0], "");
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   return map;
 }
Ejemplo n.º 2
0
  /**
   * SHA-256 hash
   *
   * @param s String
   * @return String
   */
  static String SHA_256(String s) {
    String baseString = "AT" + s;
    String result = "";
    try {
      MessageDigest md;
      md = MessageDigest.getInstance("SHA-256");
      md.update(baseString.getBytes());

      byte byteData[] = md.digest();

      for (byte aByteData : byteData) {
        String hex = Integer.toHexString(0xff & aByteData);
        if (hex.length() == 1) {
          result += "0";
        }
        result += hex;
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return result;
  }