I’m trying to implement this algorithm description from a previous question I had here in stackoverflow:
suppressing or not allowing the access time to be modified java
so I implemented as
byte[] digest = new byte[this.BUFFER];
MessageDigest md5;
try {
md5 = MessageDigest.getInstance("MD5");
while(entry.getNextEntry() != null){
ZipEntry current = entry.getNextEntry();
if(current.isDirectory()){
digest = this.encodeUTF8(current.getName());
md5.update(digest);
}
else{
entry.read(digest, 0, this.BUFFER);
md5.update(digest);
}
}
digest = md5.digest();
entry.close();
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
However, I’m getting a Exception in thread “main” java.lang.IndexOutOfBoundsException in the else statement. Does someone know why? Also, could you please tell me if my algorithm was correctly implemented?
You’re calling
getNextEntry()twice, instead of once:Use this instead:
or