是否可以在java Manifest文件中使用SHA1-Digest而无需实际使用密钥

cbl*_*ard 4 java jar manifest jarsigner

目前我们使用jarsigner签署我们的jar.然后,我们为某些特定类显示一些SHA1-Digest值,以向外部审计员证明代码在发行版之间没有变化.

我们只依靠META-INF/xxx.SF文件来获取摘要信息,我们从不使用META-INF/xxx.DSA签名块文件.

由于我们只需要在代码中进行摘要计算,因此我想知道是否可以.SF使用某些java工具生成文件,而无需实际使用密钥.

我阅读http://docs.oracle.com/javase/6/docs/technotes/tools/windows/jarsigner.html,但看起来密钥是强制性的.

mga*_*ert 7

这应该是可能的.MANIFEST.MF文件包含相应类文件的Base64编码的SHA-1.

从您的文件:

In the manifest file, the SHA digest value for each source file is the
digest (hash) of the binary data in the source file. In the .SF file,
on the other hand, the digest value for a given source file is the
hash of the three lines in the manifest file for the source file.
Run Code Online (Sandbox Code Playgroud)

因此,迭代所有类文件,计算出在MANIFEST.MF中出现的SHA-1格式,然后在SF文件中对其进行散列和格式化.

计算没有关键.

示例:考虑"jce1_2_2.jar"(或者您已正确签名的任何内容).这包含

  1. 表单的MANIFEST.MF条目

    Name: javax/crypto/KeyAgreement.class
    SHA1-Digest: c2p0JimzpV0dG+NChGLl5cI7MuY=
    <empty line>
    
    Run Code Online (Sandbox Code Playgroud)
  2. 它们是"KeyAgreement.class"的Base64(SHA1-1)(路径不相关).注意第三个空行.行结尾是CRLF(Windows).

  3. META-INF/4JCEJARS.SF条目

    Name: javax/crypto/KeyAgreement.class
    SHA1-Digest: whGBXE+AvYO6wAoVCdnocOPIrsE=
    
    Run Code Online (Sandbox Code Playgroud)

这是不是文件的哈希,而是上面三行的哈希.