java 尝试刷新“过期”密钥库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4823302/
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 08:11:52  来源:igfitidea点击:

Trying to refresh 'expired' keystore

javaantkeytooljar-signing

提问by pstanton

I am trying to re-sign some jars using the ant task 'signjar' however it's telling me "The signer certificate has expired."

我正在尝试使用 ant 任务“signjar”对一些 jar 进行重新签名,但它告诉我“签名者证书已过期”。

So I tried to re-generate the keystore hoping this would 'un-expire' it...

所以我试图重新生成密钥库,希望这会“不过期”它......

keytool -genkey -keystore mykeystore -alias myalias

keytool -genkey -keystore mykeystore -alias myalias

but after entering the keystore password i get: "keytool error: java.lang.Exception: Key pair not generated, alias already exists"

但在输入密钥库密码后,我得到:“keytool 错误:java.lang.Exception:未生成密钥对,别名已存在”

what am i doing wrong? do i need to delete the keystore to re-generate it or is there a simple way to refresh it so it's not expired?

我究竟做错了什么?我需要删除密钥库来重新生成它还是有一种简单的方法来刷新它以使其不会过期?

thanks.

谢谢。

采纳答案by maaartinus

You're mixing up the terms. A keystore contains keys, a key is something used for signing.

你混淆了条款。密钥库包含密钥,密钥用于签名。

AFAIK, you're trying to put a new key into an old keystore using an existing alias (name). Why don't you simply used a new one? Either this or deletethe old key from the keystore first. You don't need to drop the whole keystore.

AFAIK,您正在尝试使用现有别名(名称)将新密钥放入旧密钥库。你为什么不简单地使用一个新的?要么先从密钥库中删除旧密钥。您不需要删除整个密钥库。

Have a look at portecle, this simple tool allows you to manipulate the keystore more easily.

看看portecle,这个简单的工具可以让您更轻松地操作密钥库。

回答by Tara

For this simply regenerate you certificate again follow these steps.

为此,只需按照以下步骤重新生成您的证书。

   1)keytool -genkey -v -keystore mycertificate.keystore -alias mykey -keyalg 
   RSA -keysize 2048 -validity 1000
   2)  jarsigner -verbose -keystore mycertificate.keystore D:\app.apk mykey
   3) jarsigner -verify app.apk
     If it  will have done then shows a message "successfully verified"
   4) zipalign -v 4 D:\app.apk D:\signedapp.apk

  it will generate new certificate. enjoy :)