/**
* Returns a salted PBKDF2 hash of the password.
*
* @param password
* the password to hash
* @return a salted PBKDF2 hash of the password
* @throws CustomException
*/
public String createHash(char[] password) throws CustomException {
try {
// Generate a random salt
SecureRandom random = new SecureRandom();
byte[] salt = new byte[SALT_BYTE_SIZE];
random.nextBytes(salt);
// Hash the password
byte[] hash = pbkdf2(password, salt, PBKDF2_ITERATIONS, HASH_BYTE_SIZE);
return PBKDF2_ITERATIONS + ":" + toHex(salt) + ":" + toHex(hash);
}catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
throw new CustomException(e);
}
}
PasswordHashServicePBKDF2.java 文件源码
java
阅读 40
收藏 0
点赞 0
评论 0
项目:esup-ecandidat
作者:
评论列表
文章目录