简体   繁体   English

SSL设置春季启动

[英]SSL settings spring boot

I have some questions about ssl in spring boot.我对 Spring Boot 中的 ssl 有一些疑问。 I have files certifications and private key with extension .crt and .key.我有扩展名为 .crt 和 .key 的文件认证和私钥。 how can I get from them right format for settings in spring boot like this我怎样才能从他们那里得到正确的spring boot设置格式,像这样

    server.ssl.key-store-type=PKCS12
    server.ssl.key-store=classpath:keystore.p12
    server.ssl.key-store-password=password 
    server.ssl.key-alias=tomcat

To convert a certificate file and private key to PKCS#12(.p12) format, use the below command:要将证书文件和私钥转换为 PKCS#12(.p12) 格式,请使用以下命令:

openssl pkcs12 -export -out certificate.p12 -inkey privateKey.key -in certificate.crt -certfile CACert.crt

Please go through the below links for your reference on dealing with https in spring boot.请浏览以下链接,以供您在 Spring Boot 中处理 https 时参考。

  1. Enable HTTPS in Spring Boot 在 Spring Boot 中启用 HTTPS
  2. Configure HTTP to HTTPS Redirection in Spring Boot 在 Spring Boot 中配置 HTTP 到 HTTPS 重定向

I found solution.我找到了解决方案。 I got keystore use this comand:我得到了密钥库使用这个命令:

    openssl pkcs12 -export -in <mycert.crt> -inkey <mykey.key> -out keystore.p12 -name <alias>

And added keystore into application.properies并将密钥库添加到 application.properies

    #ssl
    server.port=8443
    server.ssl.enabled=true
    server.ssl.key-store-type=PKCS12
    **server.ssl.key-store=keystore/keystore.p12**
    server.ssl.key-store-password=password
    server.ssl.key-alias=alias

It is correct config.这是正确的配置。 When I use classpath:keystore.p12 it did not work.当我使用 classpath:keystore.p12 它不起作用。 Maybe it cause that I work with spring boot 2. Then I created external folder and put inside keystore.也许是因为我使用了 Spring Boot 2。然后我创建了外部文件夹并放入了密钥库。 Now it is working.现在它正在工作。

另一种选择:如果您没有(或不喜欢?)OpenSSL, https ://keystore-explorer.org/(与 keytool 不同)可以将 privatekey+certs 读入任何类型的 Java 密钥库(PKCS12、JCEKS、JKS等,但 PKCS12 通常是最好的)带有“导入密钥对”图标或菜单项。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM