Java 如何将证书文件添加/转换为 pkcs12 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20464073/
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
how to add/convert certificate file into pkcs12 file
提问by Rohit
I have received the three certificates(.CER files) to access the production server. How I am going to add/convert these certificates into PKCS12 file.
我已收到三个证书(.CER 文件)以访问生产服务器。我将如何将这些证书添加/转换为 PKCS12 文件。
回答by Atul Soman
First export your certificates to a keystore and then import the keystore as a pkcs12 file. If you jave java installed you can use keytool command to accomplish both.
1) /jre/bin/keytool -importcert -alias cert1 -keystore keystore.jks -file Cert1.cer
2) /jre/bin/keytool -importkeystore -srckeystore keystore.jks -srcalias cert1 -destkeystore keystore.p12 -deststoretype PKCS12
首先将您的证书导出到密钥库,然后将密钥库作为 pkcs12 文件导入。如果你安装了 java,你可以使用 keytool 命令来完成这两个任务。
1) /jre/bin/keytool -importcert -alias cert1 -keystore keystore.jks -file Cert1.cer
2) /jre/bin/keytool -importkeystore -srckeystore keystore.jks -srcalias cert1 -destkeystore keystore.p12 -deststoretype PKCS12
Similar steps can be done using openssl too.
也可以使用 openssl 完成类似的步骤。
回答by lake
I got the same error and when it say's 'Do you want to quit the import process? [no]:' keep typing 'no'. It finally said: Import command completed: 1 entries successfully imported, 2 entries failed or cancelled.
我遇到了同样的错误,当它说“你想退出导入过程吗?[不]:'继续输入'不'。最后说:导入命令完成:1个条目成功导入,2个条目失败或取消。
It worked and all my certs were imported into the new format correctly.
它有效并且我所有的证书都正确导入到新格式中。
回答by Kishor Jha
I just used a older version of keytool executable and the issue was resolved.
我刚刚使用了旧版本的 keytool 可执行文件,问题已解决。
回答by Zheng Yong
the server on which you sign your certification $(hostname -f).pem should have the same java version as the nodes you plan to import cert like the following:
您签署证书 $(hostname -f).pem 的服务器应该与您计划导入证书的节点具有相同的 Java 版本,如下所示:
$JAVA_HOME/bin/keytool -importcert -alias $(hostname -f) -file /opt/cloudera/security/pki/$(hostname -f).pem -keystore /opt/cloudera/security/pki/$(hostname -f).jks
$JAVA_HOME/bin/keytool -importcert -alias $(hostname -f) -file /opt/cloudera/security/pki/$(hostname -f).pem -keystore /opt/cloudera/security/pki/$(hostname - f).jks
if you take lower version on the server to sign your certification but you take new java version on the nodes for TLS/SSL, you will see the warning.
如果您在服务器上使用较低版本来签署您的证书,但您在 TLS/SSL 的节点上使用新的 java 版本,您将看到警告。