简体   繁体   English

如何从 .pem 文件将 .p12 密钥添加到 Java Spring?

[英]How to add .p12 key to Java Spring from .pem file?

I have this 3 files:我有这 3 个文件:

  • certificate.crt证书.crt
  • certificate.pem证书.pem
  • certificate.key证书.key

The certificate.crt contains: certificate.crt 包含:

-----BEGIN CERTIFICATE-----
MIIGmzCCBYOgAwIBAg etc
-----END CERTIFICATE-----

The certificate.key contains: certificate.key 包含:

-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCA bla bla
-----END RSA PRIVATE KEY-----

And the certificate.pem is more complex, it has:而 certificate.pem 更复杂,它有:

-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgk etc etc
-----END PRIVATE KEY-----
-----BEGIN CERTIFICATE-----
MIIGmzCCBYOgAwIBAg etc
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
MIIGBjCCA+6gAwIBAgIR...
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
MIIFdzCCBF+gAwIBAgIQ...
-----END CERTIFICATE-----

So, certificate.pem contains 1 private key (diferent to certificate.key) and 3 certificates (the first is same to certificate.crt)因此,certificate.pem 包含 1 个私钥(不同于 certificate.key)和 3 个证书(第一个与 certificate.crt 相同)

With this files, how can I get a.p12 file to insert into my Java Spring application?有了这些文件,我怎样才能将.p12 文件插入到我的 Java Spring 应用程序中?

I already tried with openssl convert the.pem file to a.p12 file but when I go to https//mydomain.com there is a not secure ssl message.我已经尝试使用 openssl 将 .pem 文件转换为 a.p12 文件,但是当我将 go 转换为 https//mydomain.com 时,会出现一条不安全的 ssl 消息。

I know it's too late but in case, some one will need that in the future.我知道为时已晚,但以防万一,将来有人会需要它。

sudo openssl pkcs12 -export -in certificate.crt -inkey certificate.key -out keystore.p12

Keep attention, that in most cases cert files are protected and reading operations are allowed only for root / sudo users.请注意,在大多数情况下,证书文件受到保护,并且只允许 root / sudo 用户进行读取操作。 To verify that do -> ls -al .验证 do -> ls -al

-rw----r-- 1 root root 5717 Jun 13 21:49 certificate.crt Perform operations using root / sudo privileges or change permissions using chmod/chown. -rw----r-- 1 root root 5717 Jun 13 21:49 certificate.crt使用 root / sudo 权限执行操作或使用 chmod/chown 更改权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将.p12或pem证书导入Java密钥库? - How to import a .p12 or pem certificate into a java keystore? 如何使用Java Sun Security从.p12文件提取私钥 - how to extract private key from .p12 file using java sun security 如何使用Java从系统读取p12文件? - How to read p12 file from system in Java? 将.pem文件转换为.p12以在iOS中进行推送通知 - convert .pem file to .p12 for push notification in ios 使用Java从.p12文件获取PrivateKey对象 - Getting a PrivateKey object from a .p12 file in Java 如何用Java中的.p12文件签名数据? - How to sign data with .p12 file in Java? 使用密钥、证书和 cacert 文件而不是 .p12 文件使用 Java 连接到 RabbitMQ (TLS) - Connecting using Java to RabbitMQ (TLS) with a key, a cert and a cacert file instead of a .p12 file java.security.UnrecoverableKeyException:获取密钥失败:在Java中读取.p12文件时为null - java.security.UnrecoverableKeyException: Get Key failed: null while reading .p12 file in Java 使用Scala或Java将.p12转换为.pem以在AWS SNS中注册 - Convert .p12 to .pem for registration in AWS SNS using Scala or Java 将 .p12 文件用于 SSL - 使用 Spring Boot - Using .p12 file for SSL - Using Spring Boot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM