public final class PasswordHelper
extends java.lang.Object
Based on an example published by Jerry Orr at http://blog.jerryorr.com/2012/05/secure-password-storage-lots-of-donts.html
| Constructor and Description |
|---|
PasswordHelper() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
authenticate(java.lang.String clearPassword,
byte[] encryptedPassword,
byte[] salt)
Encrypt a clear text password candidate and compare it with the given encrypted password
to determine if they match.
|
byte[] |
encryptPassword(java.lang.String password,
byte[] salt)
Encrypt a password using the "PBKDF2WithHmacSHA1" algorithm.
|
byte[] |
salt()
Generate a random, 8-byte salt value for use when encrypting a password.
|
public boolean authenticate(java.lang.String clearPassword,
byte[] encryptedPassword,
byte[] salt)
throws java.security.NoSuchAlgorithmException,
java.security.spec.InvalidKeySpecException
clearPassword - Clear text password candidate.encryptedPassword - Previously encrypted password.salt - Salt to use with encryption algorithm.True if the candidate represents the correct password, else false.java.security.NoSuchAlgorithmException - if the requested encryption algorithm is not available in the current environment.java.security.spec.InvalidKeySpecException - if the specifications for the cryptographic key are invalid.public byte[] encryptPassword(java.lang.String password,
byte[] salt)
throws java.security.NoSuchAlgorithmException,
java.security.spec.InvalidKeySpecException
password - Clear text password to encrypt.salt - Salt to use with encryption algorithm.java.security.NoSuchAlgorithmException - if the requested encryption algorithm is not available in the current environment.java.security.spec.InvalidKeySpecException - if the specifications for the cryptographic key are invalid.public byte[] salt()
throws java.security.NoSuchAlgorithmException
java.security.NoSuchAlgorithmException - if the requested encryption algorithm is not available in the current environment.