file - suppressing or not allowing the access time to be modified java -


i'm writing java class extends ant zip task particular job me. want create zip file , once file created, want suppress access time in inode can't modified or find way not let change, if file modified. reason made md5 hash depends on access time. that's giving me lot of trouble, , making access time constant solve problem. how accomplish that? thanks!

i've had solve similar problem - perhaps option you. in case, problem was:

we made jar file , ran secure hash algorithm on jar file. because jar file zip file, , zip file internally contains file metadata information including last access time, if create new jar file exact same source material, hash on new jar file doesn't match original hash (because while zip contents same, metadata stored in zip file has different file creation / access times).

basically, needed able compute secure hash compliance purposes able show contents of jar unchanged. recompiling equivalent jar ok - it's contents had identical.

we wrote simple set of tools performed secure hashes (and verifications) zip/jar files. computed 2 hashes:

  • a regular secure hash of file (which identify exact same jar - same output of standard md5sum)
  • a "content only" hash computed iterating on bytes of unpacked contents of zip/jar (and used identify recompiled jar matched original jar)

to implement content hash, used zipinputstream iterate on zip entries.

messagedigest sha1; byte[] digest;  (each zip file entry) {   if (entry represents directory)   {     sha1.update( directory name bytes utf-8 );   }   else   {     read entry bytes using zipinputstream.read()     sha1.update( bytes );   } }  digest = sha1.digest();  

see also: zipinputstream.read()

note, however, files such manifest can contain information such version of ant used create jar, , version of compiler used compile classes. thus, have compile equivalent environment hash match.

finally, doesn't cope fact zip file might contain other zip files. while straight forward enough make inspection cater , descend nested zip/jar/war files, our implementation not.


Comments