开发者

JarSigner done within java?

开发者 https://www.devze.com 2023-03-28 22:18 出处:网络
Is it possible to use the JarSigner class to sign a jar file within java? Currently I am using: String args[] = {\"-keystore\", keystore, \"-storepass\", password, jar, keyname};

Is it possible to use the JarSigner class to sign a jar file within java? Currently I am using:

String args[] = {"-keystore", keystore, "-storepass", password, jar, keyname};
JarSigner js = new JarSigner();
js.run(args);

but if 开发者_高级运维anything fails, the js.run void will call a System.exit(-1) causing my entire application to crash. I was thinking about running that inside of a thread, joining it until it completes, and checking for the return code. Just seeing if there is a more formal way of doing that... Any help would be appreciated.


I suppose you use Sun/Oracle JarSigner included in JDK tools. You have two option:

  • Reuse by copy/paste most of the run method to skip the System.exit in catch clause from the OpenJDK source for instance

  • Use JarSigner from GNU ClassPath project which start method does not invoke System.exit but throws exceptions.


If you sign only with SHA1withRSA algorithm, there is a project called zip-signer. The main target of this project is Android, but the core library of this project, "zipsigner-lib", doesn't depend on Android system so it works in PC as well. You can take a look at sample code for PC named zipsigner-cmdline.

If you need algorithms other than SHA1withRSA, though, you'll probably have to adapt source codes from the GNU ClassPath project, which is no easy task.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号