数字证书:如何使用 .cer 文件导入到 .truststore 文件中?

发布于 2024-07-10 01:45:53 字数 138 浏览 7 评论 0原文

有没有人遇到过必须处理 .truststore 文件的地方? 并知道如何将 .cer 导入 .truststore 文件?

我不确定是否必须使用Java Keytool或Linux命令(例如openssl命令)。

谢谢

Has anyone came across where they have to deal with .truststore file? and knowing how to import .cer into .truststore file?

I am not sure if I have to use Java Keytool or Linux command (such as openssl command).

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

七月上 2024-07-17 01:45:53
# Copy the certificate into the directory Java_home\Jre\Lib\Security
# Change your directory to Java_home\Jre\Lib\Security>
# Import the certificate to a trust store.

keytool -import -alias ca -file somecert.cer -keystore cacerts -storepass changeit [Return]

Trust this certificate: [Yes]

Changeit 是默认信任库密码

# Copy the certificate into the directory Java_home\Jre\Lib\Security
# Change your directory to Java_home\Jre\Lib\Security>
# Import the certificate to a trust store.

keytool -import -alias ca -file somecert.cer -keystore cacerts -storepass changeit [Return]

Trust this certificate: [Yes]

changeit is the default truststore password

昔日梦未散 2024-07-17 01:45:53

例如,您还可以通过 openssl x509 -out certfile.txt 通过管道传输 openssl s_client 输出,而不是使用 sed 过滤掉证书:

echo "" | openssl s_client -connect my.server.com:443 -showcerts 2>/dev/null | openssl x509 -out certfile.txt

Instead of using sed to filter out the certificate, you can also pipe the openssl s_client output through openssl x509 -out certfile.txt, for example:

echo "" | openssl s_client -connect my.server.com:443 -showcerts 2>/dev/null | openssl x509 -out certfile.txt
你与清晨阳光 2024-07-17 01:45:53

将 .cer 文件导入信任存储区的方式与从 Firefox 导出的文件导入 .crt 文件的方式相同。

您不必输入密钥库的别名和密码,只需键入:

keytool -v -import -file somefile.crt  -alias somecrt -keystore my-cacerts

最好使用 Java 安装中已有的 cacerts 文件 (jre\lib\security\cacerts),因为它包含安全的“流行”证书。

有关 cer 和 crt 差异的更新(只是为了澄清)
根据 Apache with SSL - How to conversion CER to CRT证书? 和用户@Spawnrider

CER 是二进制形式的 X.509 证书,采用 DER 编码。
CRT 是二进制 X.509 证书,封装在文本 (base-64) 编码中。
这不是相同的编码。

The way you import a .cer file into the trust store is the same way you'd import a .crt file from say an export from Firefox.

You do not have to put an alias and the password of the keystore, you can just type:

keytool -v -import -file somefile.crt  -alias somecrt -keystore my-cacerts

Preferably use the cacerts file that is already in your Java installation (jre\lib\security\cacerts) as it contains secure "popular" certificates.

Update regarding the differences of cer and crt (just to clarify)
According to Apache with SSL - How to convert CER to CRT certificates? and user @Spawnrider

CER is a X.509 certificate in binary form, DER encoded.
CRT is a binary X.509 certificate, encapsulated in text (base-64) encoding.
It is not the same encoding.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文