网站https加密

博客介绍了在Spring Boot项目中配置HTTPS的步骤,包括使用keytool为Tomcat生成证书、创建私钥文件,将证书拷贝到resources目录,配置Application.yml和pom.xml,添加网页并分别通过8080和443端口访问。此外,还提及使用手机号发验证码来验证用户身份。

1. 创建证书

第一步:为服务器生成证书

使用keytool 为 Tomcat 生成证书,假定目标机器的域名是“ localhost ”, keystore 文件存放在“ d:\tomcat.keystore ”,口令为“ password123 ”,使用如下命令生成:

keytool -genkey -v -alias tomcat -keyalg RSA -validity 3650  -keystore d:\tomcat.keystore -dname "CN=localhost,OU=cn,O=cn,L=cn,ST=cn,c=cn" -storepass password123 -keypass password123

Keystore放的是证书

创建私钥.cer文件。

keytool -export -alias tomcat -keystore d:\tomcat.keystore -file d:\tomcat.cer -storepass password123

2. 创建springboot项目

2.1. 拷贝证书到resources

在这里插入图片描述

2.2. Application.yml

server:
  # 服务器的HTTP端口,默认为8080
  port: 8080
  ssl:
    #文件所在位置
    key-store: classpath:tomcat.keystore
    #keystore的密码
    key-store-password: password123
    key-store-type: JKS
    key-alias: tomcat

2.3. pom.xml
build中增加以下内容

<resources>
    <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
        <excludes>
            <exclude>*.keystore</exclude>
        </excludes>
    </resource>
    <resource>
        <directory>src/main/resources</directory>
        <filtering>false</filtering>
        <includes>
            <include>*.keystore</include>
        </includes>
    </resource>
</resources>

2.4. 添加网页

在这里插入图片描述

2.5. 访问

2.5.1. 端口号8080

https://localhost:8080/index.html
在这里插入图片描述

2.5.2. 端口号改成443

https://localhost/index.html

3. 验证用户身份

用手机号发验证码

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值