Java 如何更改密钥库中密钥的别名?

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

How to change the alias of a key within a keystore?

javamaven-2java-web-startjar-signing

提问by simpatico

I signed my JWS application MemorizEasywith a key whose alias is:

我使用别名为的密钥签署了我的 JWS 应用程序MemorizEasy

memofile.reference.emma.jar=/Users/simpatico/.netbeans/6.8/modules/ext/emma.jar

I don't remember why I chose such a long alias. I suspect it was memo only, but in my project settings I have:

我不记得为什么我选择了这么长的别名。我怀疑这只是备忘录,但在我的项目设置中,我有:

jnlp.signjar.alias=memofile.reference.emma.jar=/Users/simpatico/.netbeans/6.8/modules/ext/emma.jar

I'm now updating the application and using maven I need to specify the alias as:

我现在正在更新应用程序并使用 maven 我需要将别名指定为:

<keystorealias>memofile.reference.emma.jar=/Users/simpatico/.netbeans/6.8/modules/ext/emma.jar
</keystorealias>

Yet that doesn't work. Trying another key with alias mjeeit works.

然而这行不通。尝试使用别名的另一个键mjee可以工作。

So could I change the alias of the key? If so, how? Otherwise, why wouldn't Maven accept my alias?

那么我可以更改密钥的别名吗?如果是这样,如何?否则,Maven 为什么不接受我的别名?

采纳答案by Jcs

It is possible to duplicate a key in a keystore with the keyclonecommand of keytool:

可以使用以下keyclone命令在密钥库中复制密钥keytool

keytool -keyclone -alias "your-very-very-long-alias" -dest "new-alias" -keypass keypass -new new_keypass -keystore /path/to/keystore -storepass storepass

The changealiascommand changes the alias for an existing entry:

changealias命令更改现有条目的别名:

keytool -changealias -alias "your-very-very-long-alias" -destalias "new-alias" -keypass keypass -keystore /path/to/keystore -storepass storepass

For those that want to be prompted to enter password just remove the respective password flags (changealiasexample):

对于那些想要提示输入密码的人,只需删除相应的密码标志(changealias示例):

keytool -changealias -alias "your-very-very-long-alias" -destalias "new-alias" -keystore "/path/to/keystore"