V4 -02 SpringSecurity 细致(下篇) bcript加密 md5+盐加密(不全,点击跳转即可)

105 阅读1分钟

01 FAQ分析

1. 为什么要选择SpringSecurity??

        功能强大 SpringBoot诞生后配置方面做出大量优化

盐值加密  密码+ salt 

2. SpringSecurity加密方式 ?

        Bcrypt : 底层基于随机盐的方式对密码进行hash不可逆加密

       

 实际项目中:  盐要存储到数据库 登录时候,会基于用户名,将用户信息查询出来

并基于输入的密码和数据库查询出盐进行hashmd5 进行加密, 在于数据库 存储的密码进行比对

比对结果正确 则允许登录

package com.cy.jt;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

@SpringBootTest
public class BcryptTest {
    //Spring 的测试Test可以不写public
    @Test
    public void testEncode(){
        //1. 定义一个密码
        //2. 定义加密对象
        //3. 对密码进行加密(对密码基于随机盐进行hash不可逆加密

        String password = "123456";
        BCryptPasswordEncoder encoder= new BCryptPasswordEncoder();

        Str