/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package at.it_open.openbase.security;
import java.io.FileInputStream;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
*
* @author roland
*/
public class FileHash {
public static String getHash(String file) throws IOException {
StringBuffer hexString = null;
try {
MessageDigest md = MessageDigest.getInstance("SHA-512");
FileInputStream fis = new FileInputStream(file);
byte[] dataBytes = new byte[1024];
int nread = 0;
while ((nread = fis.read(dataBytes)) != -1) {
md.update(dataBytes, 0, nread);
}
fis.close();
byte[] mdbytes = md.digest();
hexString = new StringBuffer();
for (int i = 0; i < mdbytes.length; i++) {
hexString.append(Integer.toHexString((0xFF & mdbytes[i])));
}
return hexString.toString();
} catch (NoSuchAlgorithmException e) {
}
return "";
}
}