edu.uvm.ccts.common.util.HashUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ccts-common Show documentation
Show all versions of ccts-common Show documentation
A library of useful generic objects and tools consolidated here to simplify all UVM CCTS projects
/*
* Copyright 2015 The University of Vermont and State
* Agricultural College. All rights reserved.
*
* Written by Matthew B. Storer
*
* This file is part of CCTS Common.
*
* CCTS Common is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CCTS Common is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CCTS Common. If not, see .
*/
package edu.uvm.ccts.common.util;
import org.apache.commons.codec.digest.DigestUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.security.MessageDigest;
/**
* Created by mstorer on 5/13/14.
*/
public class HashUtil {
public static String buildKey(Object ... objs) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < objs.length - 1; i ++) {
sb.append(String.valueOf(objs[i])).append("\u0000;\u0000");
}
sb.append(String.valueOf(objs[objs.length - 1]));
MessageDigest md = DigestUtils.getMd5Digest();
md.update(sb.toString().getBytes());
byte[] bytes = md.digest();
return new BigInteger(1, bytes).toString(16);
}
public static String buildChecksum(File file) throws IOException {
return DigestUtils.md5Hex(new FileInputStream(file));
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy