org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
密码,加密,解密
spring-security-crypto-5.7.3.jar

/** Copyright 2002-2011 the original author or authors.** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at** https://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/package org.springframework.security.crypto.bcrypt;import java.security.SecureRandom;
import java.util.regex.Matcher;
import java.util.regex.Pattern;import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;import org.springframework.security.crypto.password.PasswordEncoder;/*** Implementation of PasswordEncoder that uses the BCrypt strong hashing function. Clients* can optionally supply a "version" ($2a, $2b, $2y) and a "strength" (a.k.a. log rounds* in BCrypt) and a SecureRandom instance. The larger the strength parameter the more work* will have to be done (exponentially) to hash the passwords. The default value is 10.** @author Dave Syer*/
public class BCryptPasswordEncoder implements PasswordEncoder {private Pattern BCRYPT_PATTERN = Pattern.compile("\\A\\$2(a|y|b)?\\$(\\d\\d)\\$[./0-9A-Za-z]{53}");private final Log logger = LogFactory.getLog(getClass());private final int strength;private final BCryptVersion version;private final SecureRandom random;public BCryptPasswordEncoder() {this(-1);}/*** @param strength the log rounds to use, between 4 and 31*/public BCryptPasswordEncoder(int strength) {this(strength, null);}/*** @param version the version of bcrypt, can be 2a,2b,2y*/public BCryptPasswordEncoder(BCryptVersion version) {this(version, null);}/*** @param version the version of bcrypt, can be 2a,2b,2y* @param random the secure random instance to use*/public BCryptPasswordEncoder(BCryptVersion version, SecureRandom random) {this(version, -1, random);}/*** @param strength the log rounds to use, between 4 and 31* @param random the secure random instance to use*/public BCryptPasswordEncoder(int strength, SecureRandom random) {this(BCryptVersion.$2A, strength, random);}/*** @param version the version of bcrypt, can be 2a,2b,2y* @param strength the log rounds to use, between 4 and 31*/public BCryptPasswordEncoder(BCryptVersion version, int strength) {this(version, strength, null);}/*** @param version the version of bcrypt, can be 2a,2b,2y* @param strength the log rounds to use, between 4 and 31* @param random the secure random instance to use*/public BCryptPasswordEncoder(BCryptVersion version, int strength, SecureRandom random) {if (strength != -1 && (strength < BCrypt.MIN_LOG_ROUNDS || strength > BCrypt.MAX_LOG_ROUNDS)) {throw new IllegalArgumentException("Bad strength");}this.version = version;this.strength = (strength == -1) ? 10 : strength;this.random = random;}@Overridepublic String encode(CharSequence rawPassword) {if (rawPassword == null) {throw new IllegalArgumentException("rawPassword cannot be null");}String salt = getSalt();return BCrypt.hashpw(rawPassword.toString(), salt);}private String getSalt() {if (this.random != null) {return BCrypt.gensalt(this.version.getVersion(), this.strength, this.random);}return BCrypt.gensalt(this.version.getVersion(), this.strength);}@Overridepublic boolean matches(CharSequence rawPassword, String encodedPassword) {if (rawPassword == null) {throw new IllegalArgumentException("rawPassword cannot be null");}if (encodedPassword == null || encodedPassword.length() == 0) {this.logger.warn("Empty encoded password");return false;}if (!this.BCRYPT_PATTERN.matcher(encodedPassword).matches()) {this.logger.warn("Encoded password does not look like BCrypt");return false;}return BCrypt.checkpw(rawPassword.toString(), encodedPassword);}@Overridepublic boolean upgradeEncoding(String encodedPassword) {if (encodedPassword == null || encodedPassword.length() == 0) {this.logger.warn("Empty encoded password");return false;}Matcher matcher = this.BCRYPT_PATTERN.matcher(encodedPassword);if (!matcher.matches()) {throw new IllegalArgumentException("Encoded password does not look like BCrypt: " + encodedPassword);}int strength = Integer.parseInt(matcher.group(2));return strength < this.strength;}/*** Stores the default bcrypt version for use in configuration.** @author Lin Feng*/public enum BCryptVersion {$2A("$2a"),$2Y("$2y"),$2B("$2b");private final String version;BCryptVersion(String version) {this.version = version;}public String getVersion() {return this.version;}}}
相关文章:
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
密码,加密,解密 spring-security-crypto-5.7.3.jar /** Copyright 2002-2011 the original author or authors.** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with t…...
系统安全测试要怎么做?
进行系统安全测试时,可以按照以下详细的步骤进行: 1、信息收集和分析: 收集系统的相关信息,包括架构、部署环境、使用的框架和技术等。 分析系统的安全需求、威胁模型和安全策略等文档。 2、威胁建模和风险评估: …...
Golang并发模型:Goroutine 与 Channel 初探
文章目录 goroutinegoexit() channel缓冲closerangeselect goroutine goroutine 是 Go 语言中的一种轻量级线程(lightweight thread),由 Go 运行时环境管理。与传统的线程相比,goroutine 的创建和销毁的开销很小,可以…...
批量添加PPT备注
我一直都觉得,用python高效办公,是件没必要的事。。。 但直到最近写课做PPT,做了80多页PPT,要把每一页PPT的备注粘贴进去时 我觉得,有什么关系呢,一页一页粘 但是粘到5页,我感觉ctlc\v频率有点儿…...
数据挖掘之PCA-主成分分析
PCA的用处:找出反应数据中最大变差的投影(就是拉的最开)。 在减少需要分析的指标同时,尽量减少原指标包含信息的损失,以达到对所收集数据进行全面分析的目的 但是什么时候信息保留的最多呢?具体一点&#…...
人工智能-注意力机制之注意力汇聚:Nadaraya-Watson 核回归
查询(自主提示)和键(非自主提示)之间的交互形成了注意力汇聚; 注意力汇聚有选择地聚合了值(感官输入)以生成最终的输出。 本节将介绍注意力汇聚的更多细节, 以便从宏观上了解注意力机…...
<HarmonyOS第一课>1·运行Hello World【课后考核】
【习题】运行Hello World工程 判断题 1.DevEco Studio是开发HarmonyOS应用的一站式集成开发环境。 正确(True) 2.main_pages.json存放页面page路径配置信息。 正确(True) 单选题 1.在stage模型中,下列配置文件属于AppScope文件夹的是?(…...
Ubuntu18.04安装A-Loam保姆级教程
系统环境:Ubuntu18.04.6 LTS 1.A-Loam的安装前要求: 1.1 ROS安装:参考我的另一篇博客 Ubuntu18.04安装ROS-melodic保姆级教程_灬杨三岁灬的博客-CSDN博客还是那句话,有时候加了这行也不好使,我是疯狂试了20次&#…...
重生之我是一名程序员 40 ——字符串函数(1)
哈喽啊大家晚上好!今天呢给大家带来点新的东西——字符串函数strcpy。 首先,让我来给大家介绍一下它。strcpy函数是C语言中的一个字符串函数,用于将一个字符串复制到另一个字符串中。其函数原型为: char* strcpy(char* dest, co…...
Navicat 技术指引 | 连接 GaussDB 主备版
Navicat Premium(16.2.8 Windows版或以上) 已支持对GaussDB 主备版的管理和开发功能。它不仅具备轻松、便捷的可视化数据查看和编辑功能,还提供强大的高阶功能(如模型、结构同步、协同合作、数据迁移等),这…...
【git】pip install git+https://github.com/xxx/xxx替换成本地下载编译安装解决网络超时问题
目录 🌑🌑 背景 🌒 🌒作用 🌔🌔 问题 🌔🌔解决方案 🌙方法一 🌙方法二 🌝🌝我的解决方案 整理不易,欢迎一键三连…...
SQL Server对象类型(6)——4.6.存储过程和函数(Procedure和Function)
4.6. 存储过程和函数(Procedure和Function) 4.6.1. 过程和函数概念 与Oracle中类似,SQL Server中,存储过程和函数都是虚的、被定义的代码对象,它们都是由一组T-SQL或公共语言运行库(CLR)代码构成的程序,其本身并不存储数据,通过数据库或应用端调用等方式来运行,以满…...
spring @Async异步执行
在一些后台耗时的场景比如说生成统计报表,生成数据文件,执行批量任务时候,需要异步执行,先登记信息,然后异步执行批量同步返回给客户端。在spring中要想使用异步方法执行,必须使用EnableAsync注解开启async…...
#Js篇:单线程模式同步任务异步任务任务队列事件循环setTimeout() setInterval()
单线程模式 之所以采用单线程,而不是多线程,跟历史有关系。原因是不想让浏览器变得太复杂,因为多线程需要共享资源、且有可能修改彼此的运行结果,对于一种网页脚本语言来说,太复杂了。 好处 实现起来比较简单&#…...
html table样式的设计 表格边框修饰
<!DOCTYPE html> <html> <head> <meta http-equiv"Content-Type" content"text/html; charsetutf-8" /> <title>今日小说排行榜</title> <style> table {border-collapse: collapse;border: 4px double red; /*…...
2023年【危险化学品经营单位安全管理人员】考试内容及危险化学品经营单位安全管理人员最新解析
题库来源:安全生产模拟考试一点通公众号小程序 危险化学品经营单位安全管理人员考试内容是安全生产模拟考试一点通生成的,危险化学品经营单位安全管理人员证模拟考试题库是根据危险化学品经营单位安全管理人员最新版教材汇编出危险化学品经营单位安全管…...
腾讯云 小程序 SDK对象存储 COS使用记录,原生小程序写法。
最近做了一个项目,需求是上传文档,文档类型多种,图片,视频,文件,doc,xls,zip,txt 等等,而且文档类型可能是大文件,可能得上百兆,甚至超过1G。 腾讯云文档地址:https://c…...
【uniapp】本地资源图片无法通过 WXSS 获取,可以使用网络图片,或者 base64,或者使用image标签
uniapp开发 微信小程序 本地资源图片无法通过 WXSS 获取,可以使用网络图片,或者 base64,或者使用image标签。_uniapp 中的本地资源图片无法通过 wxss 获取,可以使用网络图片,或者 base64,或者_芒果大胖砸的博客-CSDN博客...
深入了解Spring Cloud中的分布式事务解决方案
引言 介绍分布式系统中事务管理的重要性,以及在云计算环境下分布式事务所面临的挑战。 传统事务和分布式事务 解释本地事务与分布式事务的区别,以及为什么在分布式环境中需要特殊的事务管理机制。 分布式事务的挑战 探讨在分布式系统中实现事务一致性所…...
安装compiler version 5
这个compiler version5 在我的资源里面可以免费下载; 另外这个东西还需要安装,安装教程在这里:Keil最新版保姆教程(解决缺少V5编译器问题) - 哔哩哔哩 (bilibili.com) 看吧安装好了year...
华为云AI开发平台ModelArts
华为云ModelArts:重塑AI开发流程的“智能引擎”与“创新加速器”! 在人工智能浪潮席卷全球的2025年,企业拥抱AI的意愿空前高涨,但技术门槛高、流程复杂、资源投入巨大的现实,却让许多创新构想止步于实验室。数据科学家…...
《Qt C++ 与 OpenCV:解锁视频播放程序设计的奥秘》
引言:探索视频播放程序设计之旅 在当今数字化时代,多媒体应用已渗透到我们生活的方方面面,从日常的视频娱乐到专业的视频监控、视频会议系统,视频播放程序作为多媒体应用的核心组成部分,扮演着至关重要的角色。无论是在个人电脑、移动设备还是智能电视等平台上,用户都期望…...
理解 MCP 工作流:使用 Ollama 和 LangChain 构建本地 MCP 客户端
🌟 什么是 MCP? 模型控制协议 (MCP) 是一种创新的协议,旨在无缝连接 AI 模型与应用程序。 MCP 是一个开源协议,它标准化了我们的 LLM 应用程序连接所需工具和数据源并与之协作的方式。 可以把它想象成你的 AI 模型 和想要使用它…...
Auto-Coder使用GPT-4o完成:在用TabPFN这个模型构建一个预测未来3天涨跌的分类任务
通过akshare库,获取股票数据,并生成TabPFN这个模型 可以识别、处理的格式,写一个完整的预处理示例,并构建一个预测未来 3 天股价涨跌的分类任务 用TabPFN这个模型构建一个预测未来 3 天股价涨跌的分类任务,进行预测并输…...
Python爬虫(一):爬虫伪装
一、网站防爬机制概述 在当今互联网环境中,具有一定规模或盈利性质的网站几乎都实施了各种防爬措施。这些措施主要分为两大类: 身份验证机制:直接将未经授权的爬虫阻挡在外反爬技术体系:通过各种技术手段增加爬虫获取数据的难度…...
Robots.txt 文件
什么是robots.txt? robots.txt 是一个位于网站根目录下的文本文件(如:https://example.com/robots.txt),它用于指导网络爬虫(如搜索引擎的蜘蛛程序)如何抓取该网站的内容。这个文件遵循 Robots…...
BCS 2025|百度副总裁陈洋:智能体在安全领域的应用实践
6月5日,2025全球数字经济大会数字安全主论坛暨北京网络安全大会在国家会议中心隆重开幕。百度副总裁陈洋受邀出席,并作《智能体在安全领域的应用实践》主题演讲,分享了在智能体在安全领域的突破性实践。他指出,百度通过将安全能力…...
12.找到字符串中所有字母异位词
🧠 题目解析 题目描述: 给定两个字符串 s 和 p,找出 s 中所有 p 的字母异位词的起始索引。 返回的答案以数组形式表示。 字母异位词定义: 若两个字符串包含的字符种类和出现次数完全相同,顺序无所谓,则互为…...
浅谈不同二分算法的查找情况
二分算法原理比较简单,但是实际的算法模板却有很多,这一切都源于二分查找问题中的复杂情况和二分算法的边界处理,以下是博主对一些二分算法查找的情况分析。 需要说明的是,以下二分算法都是基于有序序列为升序有序的情况…...
Unsafe Fileupload篇补充-木马的详细教程与木马分享(中国蚁剑方式)
在之前的皮卡丘靶场第九期Unsafe Fileupload篇中我们学习了木马的原理并且学了一个简单的木马文件 本期内容是为了更好的为大家解释木马(服务器方面的)的原理,连接,以及各种木马及连接工具的分享 文件木马:https://w…...
