将 .pk8 文件转换为 .key 文件

发布于 2024-11-30 23:42:49 字数 109 浏览 1 评论 0原文

我有一个 .pk8 文件,我想将其转换为 .key 文件格式,以便我可以将它们移动到 pkcs12 存储中,然后使用 keytool 移动到 java 密钥存储中。

请提出可能的解决方案?

I have a .pk8 file and I want to convert it into .key file format,so that I can move them into a pkcs12 store and then later to java keystore using keytool.

Please suggest possible solutions??

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

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

发布评论

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

评论(2

你对谁都笑 2024-12-07 23:42:49

首先使用 OpenSSL 命令行工具将您的 PKCS#8 文件转换为普通私钥:

openssl pkcs8 -in file.pk8 -out key.pem

如果这给您带来错误,可能是因为密钥采用 DER 格式,请尝试以下操作:

openssl pkcs8 -in file.pk8 -inform DER -out key.pem

收集您想要在 PKCS 中使用的证书#12 密钥存储并确保它们是 PEM 编码的(在文本编辑器中打开它们 - 如果文件以“----- BEGIN X.509 CERTIFICATE -----”或类似内容开头,那么你已经很好了到go):

openssl x509 -in single_cert.cer -inform DER -out single_cert.pem

打开文本编辑器,然后将所有 PEM 编码的证书加上 key.pem 的内容粘贴到该文件中,一个接一个地获取如下文件:

----- BEGIN RSA PRIVATEKEY ----- '' or another format, depends on your key
...contents of your key file
----- END RSA PRIVATEKEY -----
----- BEGIN X.509 CERTIFICATE -----
...contents of certificate 1
----- END X.509 CERTIFICATE -----
----- BEGIN X.509 CERTIFICATE -----
...contents of certificate 2
----- END X.509 CERTIFICATE -----
...

保存此文件,例如 as all .pem。要最终创建 PKCS#12 密钥存储,请发出以下命令:

openssl pkcs12 -export -in all.pem -out file.p12 -name "somename"

提供密码即可完成。 name 参数将成为您在 Java 世界中的“别名”。

Use the OpenSSL command line tool to convert your PKCS#8 file to a plain private key first:

openssl pkcs8 -in file.pk8 -out key.pem

If that gives you an error it's probably because the key is in DER format, try this then:

openssl pkcs8 -in file.pk8 -inform DER -out key.pem

Gather the certificates you want to be in your PKCS#12 key store and make sure they are PEM-encoded (open them in a text editor - if the file starts with '----- BEGIN X.509 CERTIFICATE -----' or similar then you're already good to go):

openssl x509 -in single_cert.cer -inform DER -out single_cert.pem

Open a text editor and paste all the PEM-encoded certificates plus the contents of key.pem in that file, one after the other to get a file like this:

----- BEGIN RSA PRIVATEKEY ----- '' or another format, depends on your key
...contents of your key file
----- END RSA PRIVATEKEY -----
----- BEGIN X.509 CERTIFICATE -----
...contents of certificate 1
----- END X.509 CERTIFICATE -----
----- BEGIN X.509 CERTIFICATE -----
...contents of certificate 2
----- END X.509 CERTIFICATE -----
...

Save this, e.g. as all.pem. To finally create your PKCS#12 key store, issue this command:

openssl pkcs12 -export -in all.pem -out file.p12 -name "somename"

Provide a password and your done. The name parameter is going to be your "alias" in the Java world.

牵你的手,一向走下去 2024-12-07 23:42:49

遵循本指南对我有用。具体使用 keytool-iui 导入私钥。

Following this guide worked for me. Specifically using keytool-iui to import the private key.

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