繁体   English   中英

在 Spring 启动应用程序中启用 SSL

[英]Enable SSL in Spring boot Application

如何在 Spring Boot 应用程序中使用自签名证书启用 SSL,我在属性文件中添加了配置但对我不起作用。

首先要做的是生成证书。 您可以选择不同的格式,如PKCS12JKS 我将使用 PKCS12,因为它是一种不限于 JVM 的标准格式:

$keytool -genkeypair -alias so57488831 -keyalg RSA -keysize 2048 -storetype PKCS12 -keystore so57488831.p12 -validity 365

Enter keystore password: <so57488831>
Re-enter new password: <so57488831>

What is your first and last name?
  [Unknown]:  madhead
What is the name of your organizational unit?
  [Unknown]:  N/A
What is the name of your organization?
  [Unknown]:  N/A
What is the name of your City or Locality?
  [Unknown]:  Minsk
What is the name of your State or Province?
  [Unknown]:  Minsk
What is the two-letter country code for this unit?
  [Unknown]:  BY
Is CN=madhead, OU=N/A, O=N/A, L=Minsk, ST=Minsk, C=BY correct?
  [no]:  yes

将生成一个名为so57488831.p12的文件。 将其放在项目的resources目录中: src/main/resources/so57488831.p12

配置 Spring Boot

应用程序.yml:

server:
  ssl:
    key-store-type: PKCS12
    key-store: classpath:so57488831.p12
    key-alias: so57488831
    key-store-password: so57488831

你很高兴去。 通过 HTTPS 调用您的应用程序:

在 Firefox 中看到“不受信任的证书”黄色三角形警告? 让我们来看看:

如果您有兴趣,请查看我为此问题创建的演示项目

暂无
暂无

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

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