Springboot基于BCrypt非對稱加密字符串的實(shí)現(xiàn)
1 : BCrypt簡介
在用戶模塊中,需要對于用戶的密碼進(jìn)行保護(hù),通常都會(huì)進(jìn)行加密。
我們通常對密碼進(jìn)行加密,然后存放在數(shù)據(jù)庫中,在用戶進(jìn)行登錄的時(shí)候,將其輸入的密碼進(jìn)行加密然后與數(shù)據(jù)庫中存放的密文進(jìn)行比較,以驗(yàn)證用戶密碼是否正確。
目前,MD5和BCrypt比較流行。相對來說,BCrypt比MD5更安全。
BCrypt官網(wǎng)地址:http://www.mindrot.org/projects/jBCrypt/
2 : 集成BCrypt加密及驗(yàn)證
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);
? ? }
? ? /**
? ? ?* 密碼校驗(yàn)
? ? ?*/
? ? public static boolean check(String source, String pwdCode){
? ? ? ? return BCrypt.checkpw(source, pwdCode);
? ? }
}2.3 : 驗(yàn)證
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));
}

到此這篇關(guān)于Springboot基于BCrypt非對稱加密字符串的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)Springboot BCrypt非對稱加密字符串內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- 解決Spring security5.5.7報(bào)錯(cuò)Encoded password does not look like BCrypt異常
- 使用spring?security?BCryptPasswordEncoder接入系統(tǒng)
- 如何在spring boot項(xiàng)目中使用Spring Security的BCryptPasswordEncoder類進(jìn)行相同密碼不同密文的加密和驗(yàn)證
- 一文掌握SpringSecurity?BCrypt密碼加密和解密
- SpringBoot整合BCrypt實(shí)現(xiàn)密碼加密
- Spring security BCryptPasswordEncoder密碼驗(yàn)證原理詳解
- Spring項(xiàng)目使用Maven和BCrypt實(shí)現(xiàn)修改密碼功能方式
相關(guān)文章
idea的easyCode的 MybatisPlus模板的配置詳解
這篇文章主要介紹了idea的easyCode的 MybatisPlus模板的配置詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09
如何解決@value獲取不到y(tǒng)aml數(shù)組的問題
文章介紹了在使用YAML配置文件時(shí),通過@Value注解獲取整數(shù)和數(shù)組列表的配置方法,并提供了兩種解決方案:一種適用于非嵌套列表,另一種適用于嵌套列表等復(fù)雜配置2024-11-11
SpringBoot實(shí)現(xiàn)物品點(diǎn)贊功能
這篇文章主要介紹了SpringBoot物品點(diǎn)贊功能實(shí)現(xiàn),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-04-04
解決Springboot2.1.x配置Activiti7單獨(dú)數(shù)據(jù)源問題
這篇文章主要介紹了Springboot2.1.x配置Activiti7單獨(dú)數(shù)據(jù)源問題,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-09-09
Java使用httpRequest+Jsoup爬取紅藍(lán)球號(hào)碼
本文將結(jié)合實(shí)例代碼,介紹Java使用httpRequest+Jsoup爬取紅藍(lán)球號(hào)碼,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-07-07
SpringBoot實(shí)現(xiàn)異步的八種方法
Spring Boot 的異步處理主要是通過非阻塞I/O和回調(diào)機(jī)制來實(shí)現(xiàn)的,目的是提高應(yīng)用的并發(fā)性能,它支持多種方式來創(chuàng)建異步任務(wù),本文給大家介紹了SpringBoot實(shí)現(xiàn)異步的八種方法,需要的朋友可以參考下2024-07-07

