From 2e5a681f8272594f31d789ce83cab60513687ac8 Mon Sep 17 00:00:00 2001 From: AppleOfGray Date: Fri, 17 Mar 2023 01:06:18 +0000 Subject: [PATCH] =?UTF-8?q?update=20sa-token-doc/up/password-secure.md.=20?= =?UTF-8?q?=E7=BE=A4=E5=8F=8B=E6=8F=90=E5=88=B0=E6=96=87=E6=A1=A3=E4=B8=AD?= =?UTF-8?q?=E5=8D=87=E7=BA=A7=E8=AE=B0=E5=BD=95=E5=8F=AF=E4=BB=A5=E6=89=BE?= =?UTF-8?q?=E5=88=B0=E6=AD=A4=E7=B1=BB,=20=E4=BD=86=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E8=AF=A6=E7=BB=86=E8=AF=B4=E6=98=8E=E5=85=B6?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=96=B9=E6=B3=95.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sa-token-doc/up/password-secure.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/sa-token-doc/up/password-secure.md b/sa-token-doc/up/password-secure.md index 48972ab9..df6a2ddf 100644 --- a/sa-token-doc/up/password-secure.md +++ b/sa-token-doc/up/password-secure.md @@ -76,6 +76,25 @@ String text2 = SaBase64Util.decode(base64Text); System.out.println("Base64解码后:" + text2); ``` +### BCrypt加密 +由它加密的文件可在所有支持的操作系统和处理器上进行转移 + +它的口令必须是8至56个字符,并将在内部被转化为448位的密钥 + +> 此类来自于https://github.com/jeremyh/jBCrypt/ +``` java +// 使用方法 +String pw_hash = BCrypt.hashpw(plain_password, BCrypt.gensalt()); + +// 使用checkpw方法检查被加密的字符串是否与原始字符串匹配: +BCrypt.checkpw(candidate_password, stored_hash); + +// gensalt方法提供了可选参数 (log_rounds) 来定义加盐多少,也决定了加密的复杂度: +String strong_salt = BCrypt.gensalt(10); +String stronger_salt = BCrypt.gensalt(12); +``` + +
如需更多加密算法,可参考 [Hutool-crypto: 加密](https://hutool.cn/docs/#/crypto/%E6%A6%82%E8%BF%B0)