public class PwdPbkdf2
extends java.lang.Object
| 限定符和类型 | 字段和说明 |
|---|---|
private static int |
HASH_BYTES |
private static int |
ITERATION_INDEX |
private static java.lang.String |
PBKDF2_ALGORITHM |
private static int |
PBKDF2_INDEX |
private static int |
PBKDF2_ITERATIONS |
private static int |
SALT_BYTES |
private static int |
SALT_INDEX |
| 构造器和说明 |
|---|
PwdPbkdf2() |
| 限定符和类型 | 方法和说明 |
|---|---|
static java.lang.String |
createHash(char[] password)
计算哈希值
|
static java.lang.String |
createHash(java.lang.String password)
计算哈希值
|
private static byte[] |
fromHex(java.lang.String hex)
将16进位的string转换为byte[]
|
static int |
getPbkdf2HashLength()
获取此密码哈希的长度
|
private static byte[] |
pbkdf2(char[] password,
byte[] salt,
int iterations,
int bytes)
根据密码计算pbkdf2的值
|
private static boolean |
slowEquals(byte[] a,
byte[] b)
比较哈希值的函数.
|
private static java.lang.String |
toHex(byte[] array)
将byte[]转换为16进位的string
|
static boolean |
validatePassword(char[] password,
java.lang.String goodHash)
检验密码是否正确, 即相同盐值, 迭代次数下, 与目标的哈希一样
|
static boolean |
validatePassword(java.lang.String password,
java.lang.String goodHash)
检验密码是否正确, 即相同盐值, 迭代次数下, 与目标的哈希一样
|
private static final java.lang.String PBKDF2_ALGORITHM
private static final int SALT_BYTES
private static final int HASH_BYTES
private static final int PBKDF2_ITERATIONS
private static final int ITERATION_INDEX
private static final int SALT_INDEX
private static final int PBKDF2_INDEX
public static java.lang.String createHash(java.lang.String password)
throws java.security.NoSuchAlgorithmException,
java.security.spec.InvalidKeySpecException
password - 需要加密的密码-stringjava.security.NoSuchAlgorithmExceptionjava.security.spec.InvalidKeySpecExceptionpublic static java.lang.String createHash(char[] password)
throws java.security.NoSuchAlgorithmException,
java.security.spec.InvalidKeySpecException
password - 需要加密的密码-char[]java.security.NoSuchAlgorithmExceptionjava.security.spec.InvalidKeySpecExceptionpublic static boolean validatePassword(java.lang.String password,
java.lang.String goodHash)
throws java.security.NoSuchAlgorithmException,
java.security.spec.InvalidKeySpecException
password - 需要检验的密码-stringgoodHash - 进行比较的哈希值java.security.NoSuchAlgorithmExceptionjava.security.spec.InvalidKeySpecExceptionpublic static boolean validatePassword(char[] password,
java.lang.String goodHash)
throws java.security.NoSuchAlgorithmException,
java.security.spec.InvalidKeySpecException
password - 需要检验的密码-char[]goodHash - 进行比较的哈希值java.security.NoSuchAlgorithmExceptionjava.security.spec.InvalidKeySpecExceptionpublic static int getPbkdf2HashLength()
private static boolean slowEquals(byte[] a,
byte[] b)
a - 第一个byteb - 第二个byteprivate static byte[] pbkdf2(char[] password,
byte[] salt,
int iterations,
int bytes)
throws java.security.NoSuchAlgorithmException,
java.security.spec.InvalidKeySpecException
password - 密码salt - 盐值iterations - 迭代次数(运算速度的因素)bytes - 哈希值的长度java.security.NoSuchAlgorithmExceptionjava.security.spec.InvalidKeySpecExceptionprivate static byte[] fromHex(java.lang.String hex)
hex - the hex stringprivate static java.lang.String toHex(byte[] array)
array - the byte array to convertCopyright © 2018. All rights reserved.