public class BCrypt
extends java.lang.Object
此类来自于https://github.com/jeremyh/jBCrypt/
使用方法如下:
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);
| 构造器和说明 |
|---|
BCrypt() |
| 限定符和类型 | 方法和说明 |
|---|---|
static boolean |
checkpw(java.lang.String plaintext,
java.lang.String hashed)
检查明文密码文本是否匹配加密后的文本
|
byte[] |
crypt(byte[] password,
byte[] salt,
int log_rounds,
int[] cdata)
加密密文
|
static java.lang.String |
gensalt()
生成盐
|
static java.lang.String |
gensalt(int log_rounds)
生成盐
|
static java.lang.String |
gensalt(int log_rounds,
java.security.SecureRandom random)
生成盐
|
static java.lang.String |
hashpw(java.lang.String password)
生成密文,使用长度为10的加盐方式
|
static java.lang.String |
hashpw(java.lang.String password,
java.lang.String salt)
生成密文
|
public byte[] crypt(byte[] password,
byte[] salt,
int log_rounds,
int[] cdata)
password - 明文密码salt - 加盐log_rounds - hash中叠加的对数cdata - 加密数据public static java.lang.String hashpw(java.lang.String password)
password - 需要加密的明文public static java.lang.String hashpw(java.lang.String password,
java.lang.String salt)
password - 需要加密的明文salt - 盐,使用gensalt() 生成public static java.lang.String gensalt(int log_rounds,
java.security.SecureRandom random)
log_rounds - hash中叠加的2的对数 - the work factor therefore increases as 2**log_rounds.random - SecureRandompublic static java.lang.String gensalt(int log_rounds)
log_rounds - the log2 of the number of rounds of hashing to apply - the work factor therefore increases as 2**log_rounds.public static java.lang.String gensalt()
public static boolean checkpw(java.lang.String plaintext,
java.lang.String hashed)
plaintext - 需要验证的明文密码hashed - 密文Copyright © 2022. All Rights Reserved.