如何使用纯 Java 验证签名的 JAR?

发布于 2024-07-19 17:37:36 字数 90 浏览 1 评论 0原文

我不想使用 jarsigner -verify。 没有 JAR util 包可以解决我的问题吗? 我只想验证纯 Java 中的 JAR。

I don't want to use the jarsigner -verify. Is there no JAR util package for my problem?
I just want to verfiy a JAR in pure Java.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

且行且努力 2024-07-26 17:37:36

“jarsigner”只是验证 jar 的 java 程序的一个小包装。 在你的 JDK 中有一个“tools.jar”(通常是“C:\programs\Java\jdk1.6.0_13\lib\tools.jar”或类似的东西)。 在这个库中有一个类“JarSigner”,它提供了所需的功能。 只需将“tools.jar”放在类路径中即可!

的行为

下面是一个示例程序,用于演示import sun.security.tools.JarSigner;

public class TestJarSigner {

 public static void main(String[] args) {
  JarSigner signer = new JarSigner();
  signer.run(new String[] { "-verify", "tools.jar" });
 }

}

输出为:

jar is unsigned. (signatures missing or not parsable)

如果您需要更深入地了解签名过程,资源可用

The "jarsigner" is just a small wrapper for a java program that verifies the jar. Inside your JDK there is a "tools.jar" (usally "C:\programs\Java\jdk1.6.0_13\lib\tools.jar" or something like this). Inside this library there is a class "JarSigner" that provides the desired ability. Just put the "tools.jar" on your classpath!

Heres an example program to demonstrate the behaviour

import sun.security.tools.JarSigner;

public class TestJarSigner {

 public static void main(String[] args) {
  JarSigner signer = new JarSigner();
  signer.run(new String[] { "-verify", "tools.jar" });
 }

}

Output is:

jar is unsigned. (signatures missing or not parsable)

The sources are availible if you need a deeper understanding of the signing process.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文