public static String createChecksum(String filename) throws Exception {
InputStream fis = new FileInputStream(filename);
byte[] buffer = new byte[1024];
MessageDigest complete = MessageDigest.getInstance("MD5");
int numRead;
do {
numRead = fis.read(buffer);
if (numRead > 0) {
complete.update(buffer, 0, numRead);
}
} while (numRead != -1);
fis.close();
byte[] digest = complete.digest();
StringBuffer sb = new StringBuffer();
for (byte b : digest) {
if ((int)(b & 0xff) <= 0xf)
sb.append(Integer.toHexString(0));
sb.append(Integer.toHexString((int) (b & 0xff)));
}
return sb.toString();
}
댓글 없음:
댓글 쓰기