Springboot基于BCrypt非对称加密字符串的实现
作者:message丶小和尚
本文主要介绍了Springboot基于BCrypt非对称加密字符串的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
1 : BCrypt简介
在用户模块中,需要对于用户的密码进行保护,通常都会进行加密。
我们通常对密码进行加密,然后存放在数据库中,在用户进行登录的时候,将其输入的密码进行加密然后与数据库中存放的密文进行比较,以验证用户密码是否正确。
目前,MD5和BCrypt比较流行。相对来说,BCrypt比MD5更安全。
BCrypt官网地址:http://www.mindrot.org/projects/jBCrypt/
2 : 集成BCrypt加密及验证
2.1 : 引入POM
<dependency>
<groupId>org.mindrot</groupId>
<artifactId>jbcrypt</artifactId>
<version>0.3m</version>
</dependency>2.2 : 工具类
PassWordUtil.java
package com.utils;
import org.mindrot.jbcrypt.BCrypt;
public class PassWordUtil {
/**
* 密码加密
*/
public static String encrypt(String source){
String salt = BCrypt.gensalt();
return BCrypt.hashpw(source, salt);
}
/**
* 密码校验
*/
public static boolean check(String source, String pwdCode){
return BCrypt.checkpw(source, pwdCode);
}
}2.3 : 验证
public static void main(String[] args) {
String password = "abc123&%*";
String crypt = encrypt(password);
System.out.println(crypt);
System.out.println("==========");
System.out.println(check(password, crypt));
System.out.println(check(password + "1", crypt));
}

到此这篇关于Springboot基于BCrypt非对称加密字符串的实现的文章就介绍到这了,更多相关Springboot BCrypt非对称加密字符串内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
您可能感兴趣的文章:
- 解决Spring security5.5.7报错Encoded password does not look like BCrypt异常
- 使用spring security BCryptPasswordEncoder接入系统
- 如何在spring boot项目中使用Spring Security的BCryptPasswordEncoder类进行相同密码不同密文的加密和验证
- 一文掌握SpringSecurity BCrypt密码加密和解密
- SpringBoot整合BCrypt实现密码加密
- Spring security BCryptPasswordEncoder密码验证原理详解
- Spring项目使用Maven和BCrypt实现修改密码功能方式
