java 使用带有真实证书的 jarsigner 签署 jar 文件时出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3861978/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 03:44:10  来源:igfitidea点击:

Error with signing jar files using jarsigner with a real certificate

java

提问by Q8Y

I have a problem with signing my jar files with jarsigner. I used thistutorial to sign my jar files, but with the last step(signing the jar), I got this error:

我在使用 jarsigner 签署我的 jar 文件时遇到问题。我使用教程对我的 jar 文件进行签名,但是在最后一步(对 jar 进行签名)时,出现了以下错误:

jarsigner error: java.lang.RuntimeException: keystore load: Invalid keystore format

jarsigner 错误:java.lang.RuntimeException:密钥库加载:无效的密钥库格式

and I didn't use step #10, I used instead step #5 from thissite since, I'm using a real certificate not a fake one ...

我没有使用第 10 步,而是使用了网站的第 5 步,因为我使用的是真实证书而不是假证书......

Note: I'm having my certificate in .spc& .pvkformat...

注意:我的证书是.spc&.pvk格式的...

But, since I'm using jarsigner, I have to convert them to .p12format. So, I convert them first to .pfxusing pvkimprt.exethen to .p12. I used the method that I specified in the link that I mentioned it before.

但是,由于我使用的是 jarsigner,我必须将它们转换为.p12格式。因此,我首先将它们转换为.pfx使用pvkimprt.exe然后转换为.p12. 我使用了我在之前提到的链接中指定的方法。

Also, I tried to create a fake certificate to make sure that the problem is not from the pvkimprt.exetool or from the certificate. It gave me the same error.

此外,我尝试创建一个假证书,以确保问题不是来自pvkimprt.exe工具或证书。它给了我同样的错误。

The certificate is just fine. So, where is the problem came from?

证书就好了。那么,问题出在哪里呢?

回答by Jcs

The error you are facing indicates that jarsigner does not understand the format of the keystore containing the key.

您面临的错误表明 jarsigner 不了解包含密钥的密钥库的格式。

If you converted your key & certificate into a PKCS#12 file you have to specify the type of used keystore to jarsigner with the -storetype PKCS12command line option and the P12 password with -storepass mystorepassword

如果您将密钥和证书转换为 PKCS#12 文件,则必须使用-storetype PKCS12命令行选项将使用的密钥库的类型指定给 jarsigner,并使用 P12 密码指定-storepass mystorepassword

(actually most of the time .pfx and .p12 are used for the same file format therefore I am not sure that the firefox import/export step in the tutorial is mandated)

(实际上大部分时间 .pfx 和 .p12 用于相同的文件格式,因此我不确定教程中的 firefox 导入/导出步骤是强制要求的)

回答by Dawn

Not really an answer, just a comment - I found that the upper case was crucial - "pkcs12" didn't work but "PKCS12" did, using Jcs's answer.

不是真正的答案,只是评论-我发现大写字母至关重要-使用 Jcs 的答案,“pkcs12”不起作用但“PKCS12”起作用了。

回答by kunal kishor

This is what I did and that worked:

这就是我所做的并且有效:

<ant:signjar alias="le-f0b73c88-1f82-4497-8c3f-e10d399b4c9c" storetype="pkcs12"
   storepass="fount-current"  
   keystore="/vobs/oam_base/loadbuild_tools/common/src/conf/kunal.pfx">

Store pass should be the lower case, this is the working order or arguments, some time wrong order with throw the runtime padding exception.

Store pass 应该是小写,这是工作顺序或参数,有时错误的顺序会引发运行时填充异常。

[signjar] jarsigner error: java.lang.RuntimeException: keystore load:

[signjar] jarsigner 错误:java.lang.RuntimeException:密钥库加载: