public class PasswordHash extends Object
String password = "123456"; String ciphertext = PasswordHash.DEFAULT.createHash(password); boolean success = PasswordHash.DEFAULT.validatePassword(password, ciphertext);
| 限定符和类型 | 字段和说明 |
|---|---|
static PasswordHash |
DEFAULT |
| 构造器和说明 |
|---|
PasswordHash(int charSize,
int pbkdf2Iterations)
构造函数
|
PasswordHash(int saltSize,
int hashSize,
int pbkdf2Iterations)
构造函数
|
| 限定符和类型 | 方法和说明 |
|---|---|
String |
createHash(char[] password)
加盐处理密码,返回处理后的hash
|
String |
createHash(String password)
加盐处理密码,返回处理后的hash
|
boolean |
validatePassword(char[] password,
String correctHash)
验证密码与 盐渍hash 是否匹配
return true 表示匹配,反之则false
|
boolean |
validatePassword(String password,
String correctHash)
验证密码与 盐渍hash 是否匹配
return true 表示匹配,反之则false
|
public static final PasswordHash DEFAULT
public PasswordHash(int charSize,
int pbkdf2Iterations)
charSize - 字符个数, 其中salt和hash各占一半pbkdf2Iterations - 重复计算次数, 这个数字太大会影响速度, 最好不要超过1000public PasswordHash(int saltSize,
int hashSize,
int pbkdf2Iterations)
saltSize - salt字符个数hashSize - hash字符个数pbkdf2Iterations - 重复计算次数, 这个数字太大会影响速度, 最好不要超过1000public String createHash(String password) throws NoSuchAlgorithmException, InvalidKeySpecException
password - NoSuchAlgorithmExceptionInvalidKeySpecExceptionpublic String createHash(char[] password) throws NoSuchAlgorithmException, InvalidKeySpecException
password - NoSuchAlgorithmExceptionInvalidKeySpecExceptionpublic boolean validatePassword(String password, String correctHash) throws NoSuchAlgorithmException, InvalidKeySpecException
return true 表示匹配,反之则false
password - correctHash - NoSuchAlgorithmExceptionInvalidKeySpecExceptionpublic boolean validatePassword(char[] password,
String correctHash)
throws NoSuchAlgorithmException,
InvalidKeySpecException
return true 表示匹配,反之则false
password - correctHash - NoSuchAlgorithmExceptionInvalidKeySpecExceptionCopyright © 2020. All rights reserved.