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...
VB.net复制Ntag213卡写入UID
本示例使用的发卡器:https://item.taobao.com/item.htm?ftt&id615391857885 一、读取旧Ntag卡的UID和数据 Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click轻松读卡技术支持:网站:Dim i, j As IntegerDim cardidhex, …...
2.Vue编写一个app
1.src中重要的组成 1.1main.ts // 引入createApp用于创建应用 import { createApp } from "vue"; // 引用App根组件 import App from ./App.vue;createApp(App).mount(#app)1.2 App.vue 其中要写三种标签 <template> <!--html--> </template>…...
MVC 数据库
MVC 数据库 引言 在软件开发领域,Model-View-Controller(MVC)是一种流行的软件架构模式,它将应用程序分为三个核心组件:模型(Model)、视图(View)和控制器(Controller)。这种模式有助于提高代码的可维护性和可扩展性。本文将深入探讨MVC架构与数据库之间的关系,以…...
CRMEB 框架中 PHP 上传扩展开发:涵盖本地上传及阿里云 OSS、腾讯云 COS、七牛云
目前已有本地上传、阿里云OSS上传、腾讯云COS上传、七牛云上传扩展 扩展入口文件 文件目录 crmeb\services\upload\Upload.php namespace crmeb\services\upload;use crmeb\basic\BaseManager; use think\facade\Config;/*** Class Upload* package crmeb\services\upload* …...
python报错No module named ‘tensorflow.keras‘
是由于不同版本的tensorflow下的keras所在的路径不同,结合所安装的tensorflow的目录结构修改from语句即可。 原语句: from tensorflow.keras.layers import Conv1D, MaxPooling1D, LSTM, Dense 修改后: from tensorflow.python.keras.lay…...
深度学习水论文:mamba+图像增强
🧀当前视觉领域对高效长序列建模需求激增,对Mamba图像增强这方向的研究自然也逐渐火热。原因在于其高效长程建模,以及动态计算优势,在图像质量提升和细节恢复方面有难以替代的作用。 🧀因此短时间内,就有不…...
Unity UGUI Button事件流程
场景结构 测试代码 public class TestBtn : MonoBehaviour {void Start(){var btn GetComponent<Button>();btn.onClick.AddListener(OnClick);}private void OnClick(){Debug.Log("666");}}当添加事件时 // 实例化一个ButtonClickedEvent的事件 [Formerl…...
如何应对敏捷转型中的团队阻力
应对敏捷转型中的团队阻力需要明确沟通敏捷转型目的、提升团队参与感、提供充分的培训与支持、逐步推进敏捷实践、建立清晰的奖励和反馈机制。其中,明确沟通敏捷转型目的尤为关键,团队成员只有清晰理解转型背后的原因和利益,才能降低对变化的…...
基于鸿蒙(HarmonyOS5)的打车小程序
1. 开发环境准备 安装DevEco Studio (鸿蒙官方IDE)配置HarmonyOS SDK申请开发者账号和必要的API密钥 2. 项目结构设计 ├── entry │ ├── src │ │ ├── main │ │ │ ├── ets │ │ │ │ ├── pages │ │ │ │ │ ├── H…...
Monorepo架构: Nx Cloud 扩展能力与缓存加速
借助 Nx Cloud 实现项目协同与加速构建 1 ) 缓存工作原理分析 在了解了本地缓存和远程缓存之后,我们来探究缓存是如何工作的。以计算文件的哈希串为例,若后续运行任务时文件哈希串未变,系统会直接使用对应的输出和制品文件。 2 …...
