SUP pressing或不允许的访问时间被修改的java [英] suppressing or not allowing the access time to be modified java

查看:122
本文介绍了SUP pressing或不允许的访问时间被修改的java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个Java类延伸的Ant任务邮编为我做某项工作。我想创建一个zip文件,一旦创建该文件,我想用晚餐preSS在inode,所以我不能修改或找到一种方法,不让它改变访问时,即使该文件是改性。这其中的原因是我做了一个MD5哈希值依赖于访问时间。因此,这是给我带来很多麻烦,并且使存取时间常数能解决我的问题。
现在是否有人我会如何实现这一目标?
谢谢!

I'm writing a Java Class which extends Ant Zip Task to do a particular job for me. I want to create a zip file and once that file is created, I want to suppress the access time in the inode so I can't be modified or find a way to not let it change, even if the file is modified. The reason for that is I made a md5 hash which depends on the access time. Thus that's giving me a lot of trouble, and making the access time constant will solve my problem. Does someone now how would I accomplish that? Thanks!

推荐答案

我不得不pviously解决了类似的问题$ P $ - 也许这是一个选择。对我来说,问题是:

I've had to solve a similar problem previously - perhaps this is an option for you. In my case, the problem was:

我们做了一个jar文件,然后跑了jar文件的安全散列算法。由于jar文件确实是一个zip文件和压缩文件内部包含文件的元数据信息,包括上次访问时间,如果我们创建一个从的完全相同的源材料的,那么就散了新的jar文件新的jar文件不匹配原始哈希值(因为在压缩内容是相同的,存储在zip文件中的元数据有不同的文件的创建/访问时间)。

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

基本上,我们需要的是能够计算为合规的目的能够容易地显示一个罐子的内容保持不变,安全散列。重新编译等效罐子是确定的 - 它只是使的内容的必须是相同的。

Basically, we needed to be able to compute a secure hash for compliance purposes to be able to easily show that the contents of a jar was unchanged. Recompiling an equivalent jar was ok - it's just that the contents had to be identical.

我们写了一组简单的进行安全哈希值(和验证)专为ZIP / JAR文件的工具。它计算两个哈希:

We wrote a simple set of tools that performed secure hashes (and verifications) specifically for zip/jar files. It computed two hashes:


  • 该文件的定期安全散列(这将确定的完全一样的罐子的 - 这将是同样作为标准的md5sum输出)

  • 一个内容仅,这是通过循环的拉链/罐的解压缩内容的字节计算(并因此可被用于识别一个重新编译罐子匹配原始罐子)散列

  • a regular secure hash of the file (which would identify the exact same jar - this would be the same as the output of your standard md5sum)
  • a "content only" hash which was computed by iterating over the bytes of the unpacked contents of the zip/jar (and thus could be used to identify that a recompiled jar matched the original jar)

要实现内容仅散,我们用的 ZipInputStream 遍历ZIP条目。

To implement the content only hash, we used a ZipInputStream to iterate over the zip entries.

MessageDigest sha1;
byte[] digest;

for (each zip file entry)
{
  if (entry represents a directory)
  {
    sha1.update( directory name bytes as UTF-8 );
  }
  else
  {
    read the entry bytes using ZipInputStream.read()
    sha1.update( bytes );
  }
}

digest = sha1.digest(); 

参见:<一href=\"http://docs.oracle.com/javase/6/docs/api/java/util/zip/ZipInputStream.html#read%28byte%5b%5d,%20int,%20int%29\"相对=nofollow> ZipInputStream.read()

请注意,然而,一些文件,例如清单可以包含信息,例如用于创建罐子版本蚂蚁,和用于编译的类的编译器的版本。因此,你必须从同等环境的哈希匹配编译。

Note, however, that some files such as the manifest can contain information such as the version of ant used to create the jar, and the version of the compiler used to compile the classes. Thus, you have to compile from an equivalent environment for the hash to match.

最后,这不符合事实的zip文件本身可能包含其他zip文件处理。虽然这将是直截了当足以让检查迎合这一点,并陷入嵌套ZIP / JAR / WAR文件,我们的实现没有。

Finally, this doesn't cope with the fact that a zip file might itself contain other zip files. While it would be straight forward enough to make the inspection cater for this and descend into nested zip/jar/war files, our implementation does not.

这篇关于SUP pressing或不允许的访问时间被修改的java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆