public static Pair<String, String> getImageBytes() {
    try {
      URL url =
          new URL("http://localhost/captcha.php?verify=98818D40B83AECCFB7AFD7FD9653E1037519AC61");

      InputStream inputStream = url.openStream();
      ByteArrayOutputStream output = new ByteArrayOutputStream();
      byte[] buffer = new byte[1024];
      int n = 0;
      while (-1 != (n = inputStream.read(buffer))) {
        output.write(buffer, 0, n);
      }
      String imgByte = HexTool.toString(output.toByteArray());
      return new Pair(
          imgByte.substring(39, imgByte.length()), output.toString().split("CAPTCHA")[0]);
    } catch (IOException ex) {
      File directory = new File(IMG_DIRECTORY);
      if (!directory.exists()) {
        System.err.println("lieDetector folder does not exist!");
        return null;
      }
      String[] filename = directory.list();
      String answer = filename[server.Randomizer.nextInt(filename.length)];
      answer = answer.substring(0, answer.length() - 4);
      try {
        return new Pair(
            HexTool.toString(getBytesFromFile(new File(IMG_DIRECTORY + answer + ".jpg"))), answer);
      } catch (IOException e) {
      }
    }
    return null;
  }
示例#2
0
 public String toString(final boolean b) {
   String nows = "";
   if (arr.length - pos > 0) {
     byte[] now = new byte[arr.length - pos];
     System.arraycopy(arr, pos, now, 0, arr.length - pos);
     nows = HexTool.toString(now);
   }
   if (b) {
     return "All: " + HexTool.toString(arr) + "\nNow: " + nows;
   } else {
     return "Data: " + nows;
   }
 }
示例#3
0
 private static boolean checkHash(String hash, String type, String password) {
   try {
     MessageDigest digester = MessageDigest.getInstance(type);
     digester.update(password.getBytes("UTF-8"), 0, password.length());
     return HexTool.toString(digester.digest()).replace(" ", "").toLowerCase().equals(hash);
   } catch (Exception e) {
     throw new RuntimeException("Encoding the string failed", e);
   }
 }
示例#4
0
 private static final String toSimpleHexString(final byte[] bytes) {
   return HexTool.toString(bytes).replace(" ", "").toLowerCase();
 }