Java 将 .cer 证书转换为 .jks
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30352681/
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
Convert .cer certificate to .jks
提问by arikabc
I need to convert a .cer
file to a .jks
file.
I saw a few questions about it, but haven't seen a solution to what I need.
我需要将.cer
文件转换为.jks
文件。我看到了一些关于它的问题,但还没有看到我需要的解决方案。
I don't need it in order to add it to my local certificates, but as a file to upload to a server. I also need to do it only once, and not programmatically. There's this thread Converting .cer to .jks using javaand the author says he had done it successfully, but I couldn't comment to his last reply as I don't have enough reputation, nor could I send him a personal message and ask him.
我不需要它来将它添加到我的本地证书中,而是作为一个文件上传到服务器。我也只需要做一次,而不是以编程方式。有这个线程使用 java 将 .cer 转换为 .jks,作者说他已经成功完成了,但我无法对他的最后回复发表评论,因为我没有足够的声誉,也无法向他发送个人消息并询问他。
So if anyone knows of a simple way to do so, I'll be glad to hear.
因此,如果有人知道这样做的简单方法,我会很高兴听到。
回答by Umberto Raimondi
Just to be sure that this is really the "conversion" you need, please note that jks
files are keystores, a file format used to store more than one certificate and allows you to retrieve them programmatically using the Java security API, it's not a one-to-one conversion between equivalent formats.
只是为了确保这确实是您需要的“转换”,请注意jks
文件是密钥库,一种用于存储多个证书的文件格式,并允许您使用 Java 安全 API 以编程方式检索它们,它不是一个 -等效格式之间的一对一转换。
So, if you just want to import that certificate in a new ad-hoc keystore you can do it with Keystore Explorer, a graphical tool. You'll be able to modify the keystore and the certificates contained therein like you would have done with the java terminal utilities like keytool
(but in a more accessible way).
因此,如果您只想将该证书导入到新的临时密钥库中,您可以使用Keystore Explorer(一种图形工具)来完成。您将能够像使用 java 终端实用程序一样修改密钥库和其中包含的证书keytool
(但以更易于访问的方式)。
回答by David Lavender
keytool
comes with the JDK installation (in the bin
folder):
keytool
附带JDK安装(在bin
文件夹中):
keytool -importcert -file "your.cer" -keystore your.jks -alias "<anything>"
This will create a new keystore and add just your certificate to it.
这将创建一个新的密钥库并将您的证书添加到其中。
So, you can't converta certificate to a keystore: you adda certificate to a keystore.
因此,您无法将证书转换为密钥库:您将证书添加到密钥库。
回答by amiri_mak
Export a certificate from a keystore:
从密钥库导出证书:
keytool -export -alias mydomain -file mydomain.crt -keystore keystore.jks
回答by Mukti
Use the following will help
使用以下方法会有所帮助
keytool -import -v -trustcacerts -alias keyAlias -file server.cer -keystore cacerts.jks -keypass changeit
keytool -import -v -trustcacerts -alias keyAlias -file server.cer -keystore cacerts.jks -keypass changeit