Example #1
0
  public static byte[] HMAC(byte[] key, byte[] message) {
    byte[] paddedKey = padKey(key);

    byte[] ipadXorKey = Util.xor(IPAD, paddedKey);
    byte[] opadXorKey = Util.xor(OPAD, paddedKey);

    byte[] iPadDigest = SHA256.digest(Util.concat(ipadXorKey, message));
    byte[] hmac = SHA256.digest(Util.concat(opadXorKey, iPadDigest));

    return hmac;
  }
Example #2
0
  /** Hash one or two MPIs. To hash only one MPI, b may be set to NULL. */
  public static MPI hash(int version, MPI a, MPI b, Provider prov) throws OTRException {
    int totalsize = 1 + 4 + a.getLength();
    if (b != null) {
      totalsize += 4 + b.getLength();
    }
    byte[] buf = new byte[totalsize];
    OutBuf obuf = new OutBuf(buf);

    obuf.writeByte((byte) version);
    obuf.writeUInt(a.getLength());
    a.writeRaw(obuf);

    if (b != null) {
      obuf.writeUInt(b.getLength());
      b.writeRaw(obuf);
    }
    byte[] out = obuf.getBytes();
    SHA256 sha = prov.getSHA256();
    byte[] digest = sha.hash(out);
    return new MPI(digest);
  }
Example #3
0
  public void go() {
    FileList fl = null;
    try {
      fl = new FileList(inputPath);
      fl.read();
    } catch (IOException e) {
      e.printStackTrace();
      System.exit(-1);
    }

    Queue<File> filesQ = fl.getFiles();

    LOG.info("Found " + filesQ.size() + " files to process");

    int c = 1;
    for (File file : filesQ) {
      String sum = null;
      String date = null;
      String type = getType(file);
      System.out.print(c + " ");
      if ((c % 20) == 0) {
        System.out.println();
      }
      c++;

      if (imageFile(type)) {
        try {
          sum = SHA256.digest(file);
        } catch (IOException e) {
          LOG.info("NOSHA: IO: " + file.getAbsolutePath());
        }

        try {
          date = getDate(file);
        } catch (IOException e) {
          LOG.info("NODATE: IO: " + file.getAbsolutePath());
        }

        if (sum != null && date != null) {
          storePhotoInfo(sum, date, file.getAbsolutePath());
        }
      } else {
        LOG.info("SKIP: skipping non-image file: " + file.getAbsolutePath());
      }
    }

    for (Photo p : pstore.getPhotos()) {
      savePhoto(p);
    }
  }
Example #4
0
  private void savePhoto(Photo p) {
    String date = p.getDate();
    date = date.substring(0, date.indexOf("T"));
    String[] dateParts = date.split("-");
    String year = dateParts[0];
    String month = dateParts[1];
    String day = dateParts[2];

    String outputDir = outputPath + "/" + year + "/" + month + "/" + day;

    File source = new File(p.getPaths().get(0)); // take the first one -
    // doesn't really
    // matter.
    File target = getTargetFile(outputDir, source.getName());
    File outputDirF = new File(outputDir);

    outputDirF.mkdirs();

    try {
      FileUtils.copyFile(source, target);
      LOG.info("COPY: " + source.getAbsolutePath() + " to " + target.getAbsolutePath());
    } catch (IOException e) {
      LOG.info("FAILCOPY: " + source.getAbsolutePath() + " to " + target.getAbsolutePath());
    }

    String copySum = null;
    try {
      copySum = SHA256.digest(target);
    } catch (IOException e) {
      LOG.info("NOSHACOPY: IO: " + target.getAbsolutePath());
    }

    if (copySum.equals(p.getSha256())) {
      LOG.info("VALIDCOPY: " + target.getAbsolutePath());
    } else {
      LOG.info("INVALID: " + target.getAbsolutePath());
    }

    try {
      writeTargetInfo(target, p);
    } catch (IOException e) {
      LOG.info("METAFAIL: " + target.getAbsolutePath());
    }
  }
Example #5
0
  private static byte[] padKey(byte[] key) {

    byte[] paddedKey = new byte[BLOCK_SIZE];
    if (key.length > BLOCK_SIZE) {
      key = SHA256.digest(key);
    }
    if (key.length < BLOCK_SIZE) {
      final int requiredZeroBytes = BLOCK_SIZE - key.length;
      byte[] zeroBytes = new byte[requiredZeroBytes];
      for (int i = 0; i < requiredZeroBytes; i++) {
        zeroBytes[i] = 0b00000000;
      }
      paddedKey = Util.concat(key, zeroBytes);
    }

    if (key.length == BLOCK_SIZE) {
      paddedKey = key;
    }
    return paddedKey;
  }
Example #6
0
  private void browseActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_browseActionPerformed

    // Choosing the file
    JFileChooser fileChooser = new JFileChooser();
    int retVal = fileChooser.showOpenDialog(this);
    if (retVal == JFileChooser.APPROVE_OPTION) {

      file = fileChooser.getSelectedFile();
      fileSize = (int) file.length();
      System.out.println(file.getAbsolutePath());
      System.out.println(file.getPath());
      fileName.setText(file.getName());
      fName = file.getName();
      try {
        String str = fileReader.readFile(file.getAbsolutePath());
        String HexSignature = SHA256.main(str);
        JOptionPane.showMessageDialog(rootPane, "File's Signature:" + HexSignature);
      } catch (IOException ex) {
        Logger.getLogger(ClientLoader.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
    // TODO add your handling code here:
  } // GEN-LAST:event_browseActionPerformed
Example #7
0
  public static void main(String[] args) {
    // TODO Auto-generated method stub
    String[] appNames = {
      "58tongcheng",
      "aiqiyi",
      "baiduditu",
      "baidunuomi",
      "baiduwaimai",
      "chunyuyisheng",
      "dazhongdianping",
      "didichuxing",
      "duomiyinyue",
      "edaijia",
      "ganji",
      "jingdong",
      "jinritoutiao",
      "kugouyinyue",
      "lanrentingshu",
      "leshi",
      "maimai",
      "meilishuo",
      "meituan",
      "mojitianqi",
      "momo",
      "maoyandianying",
      "qingtingfm",
      "qq",
      "qqkongjian",
      "qqtongbuzhushou",
      "qqyouxiang",
      "saomiaoquannengwang",
      "souhushipin",
      "sougoushurufa",
      "taobao",
      "tengxunshipin",
      "tianmao",
      "ucliulanqi",
      "wangxin",
      "wangyigongkaike",
      "wangyixinwen",
      "wangyiyouxiang",
      "wangyiyunketang",
      "weixin",
      "weizhibiji",
      "xinlangweibo",
      "youdaocidian",
      "youdaoyunbiji",
      "youku",
      "youxin",
      "yy",
      "zhangyue",
      "zhifubao",
      "zuoyebang"
    };
    // for (int i = 0; i < appMarket.length; i++) {

    for (int j = 0; j < appNames.length; j++) {
      String filePath = "F:/app/" + 91 + "/" + appNames[j] + ".apk";
      SHA256 sha256 = new SHA256();
      sha256.SHA256(filePath);
      System.out.println(filePath + sha256.sha256);
    }
  }