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; }
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); } }
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()); } }
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; }