Class PasswordUtils
java.lang.Object
tech.riemann.nif.auth.encode.PasswordUtils
密码加密工具类
默认 encode(String) 使用 PBKDF2WithHmacSHA256(随机盐 + 可配置迭代次数,默认 10 万次),
match(String, String) 自动识别密码格式:
- PBKDF2 格式(Base64 编码,64 字符)→ PBKDF2 验证
- 旧版 MD5 随机盐格式(48 字符)→ MD5 验证(渐进迁移兼容,老密码仍可登录)
PasswordMatcher.needsRehash(String) 判断并重哈希升级。- Author:
- Kerbores(kerbores@riemann.tech)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanDeprecated.static String加密(默认 PBKDF2WithHmacSHA256,随机盐 + 10 万次迭代)static StringDeprecated.4.2.0 起使用encodeByPBKDF2(String)替代static String加盐迭代多次摘要static StringencodeByPBKDF2(String password) static StringencodeByPBKDF2(String password, int iterations) PBKDF2 加密(指定迭代次数,供配置化使用)static booleanisPBKDF2Format(String encoded) 判断是否为 PBKDF2 格式static boolean验证密码(自动识别格式,默认迭代次数)static boolean验证密码(自动识别格式,指定 PBKDF2 迭代次数)static booleanmatchesByPBKDF2(String rawPassword, String encodedPassword) static booleanmatchesByPBKDF2(String rawPassword, String encodedPassword, int iterations) PBKDF2 验证(指定迭代次数,供配置化使用)static StringrandomSaltEncode(String password) MD5随机盐摘要static StringrandomSaltEncode(String password, int iterations) MD5随机盐摘要static booleanrandomSaltVerify(String password, String md5) MD5随机盐摘要验证static booleanrandomSaltVerify(String password, String md5, int iterations) MD5随机盐摘要验证
-
Constructor Details
-
PasswordUtils
public PasswordUtils()
-
-
Method Details
-
encode
-
encode
Deprecated.4.2.0 起使用encodeByPBKDF2(String)替代MD5固定盐多次摘要- Parameters:
password- 明文密码salt- 加密盐- Returns:
- 密文
-
encodeByPBKDF2
-
encodeByPBKDF2
-
check
@Deprecated(since="4.2.0") public static boolean check(String rawPassword, String salt, String password) Deprecated.4.2.0 起使用matchesByPBKDF2(String, String)替代MD5固定盐密码匹配- Parameters:
rawPassword- 明文密码salt- 盐password- 密文- Returns:
- 是否匹配
-
matchesByPBKDF2
-
matchesByPBKDF2
-
isPBKDF2Format
判断是否为 PBKDF2 格式PBKDF2 格式特征:Base64(16字节盐 + 32字节哈希) = 48 字节 = 64 字符
- Parameters:
encoded- 加密后的密码- Returns:
- true 表示 PBKDF2 格式
-
randomSaltEncode
-
randomSaltEncode
-
randomSaltVerify
-
randomSaltVerify
-
encode
-
match
-
match
-
matchesByPBKDF2(String, String)替代