JAVA:如何获取证书 (crt) 文件的密钥库文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4022604/
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
JAVA: how to obtain keystore file for a certification (crt) file
提问by Muhammad Hewedy
HI All,
大家好,
I have a .crt file and I need to get the associated keystore file. How to do so?
我有一个 .crt 文件,我需要获取关联的密钥库文件。怎么做?
Is keytool
is helpful in that?
在这keytool
方面有帮助吗?
Thanks.
谢谢。
采纳答案by ruruskyi
In JDK8 or higher:
在 JDK8 或更高版本中:
Command below creates empty store and imports your certificate into the keystore:
下面的命令创建空存储并将您的证书导入密钥库:
keytool -import -alias alias -file cert_file.crt -keypass keypass -keystore yourkeystore.jks -storepass Hello1
In JDK7:
在 JDK7 中:
Older versions of JDK7 create non-empty keystore which then needs to be cleared. Below is how you do that.
旧版本的 JDK7 创建非空密钥库,然后需要清除它。下面是你如何做到这一点。
Create store with temporary key inside:
在内部创建带有临时密钥的商店:
keytool -genkey -alias temp -keystore yourkeystore.jks -storepass Hello1
Then delete existing entry:
然后删除现有条目:
keytool -delete -alias temp -keystore yourkeystore.jks -storepass Hello1
Now you've got empty store. You can check that it's empty:
现在你的商店是空的。您可以检查它是否为空:
keytool -list -keystore yourkeystore.jks -storepass Hello1
Then import your certificate to the store:
然后将您的证书导入到商店:
keytool -import -alias alias -file cert_file.crt -keypass keypass -keystore yourkeystore.jks -storepass Hello1
And off you go!
你走吧!
回答by ch4nd4n
Yes, for eg.
keytool -genkey -alias duke -keypass dukekeypasswd
from (http://download.oracle.com/javase/1.4.2/docs/tooldocs/windows/keytool.html)
是的,例如。
keytool -genkey -alias duke -keypass dukekeypasswd 来自 (http://download.oracle.com/javase/1.4.2/docs/tooldocs/windows/keytool.html)