I have two small snippets for calculating SHA1.
One is very fast but it seems that it isn\'t correct and the other is very slow but correct.
I think the F
Do this:
MessageDigest md = MessageDigest.getInstance("SHA1");
InputStream in = new FileInputStream("hereyourinputfilename");
byte[] buf = new byte[8192];
for (;;) {
int len = in.read(buf);
if (len < 0)
break;
md.update(buf, 0, len);
}
in.close();
byte[] hash = md.digest();
Performance comes from handling data by blocks. An 8 kB buffer, as here, ought to be blocky enough. You do not have to use a BufferedInputStream
since the 8 kB buffer also serves as I/O buffer.