Package org.xipki.ca.gateway
Class PasswordHash
- java.lang.Object
-
- org.xipki.ca.gateway.PasswordHash
-
public class PasswordHash extends Object
PBKDF2 salted password hashing.- Author:
- havoc AT defuse.ca, www: http://crackstation.net/hashing-security.htm
-
-
Field Summary
Fields Modifier and Type Field Description static intDERIVED_KEY_SIZEstatic intITERATION_INDEXstatic intPBKDF2_INDEXstatic intPBKDF2_ITERATIONSstatic intSALT_BYTE_SIZEstatic intSALT_INDEX
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringcreateHash(byte[] password)Returns a salted PBKDF2 hash of the password.static StringcreateHash(byte[] password, int saltSize, int iterations, int dkSize)Returns a salted PBKDF2 hash of the password.static StringcreateHash(String password)Returns a salted PBKDF2 hash of the password.static byte[]pbkdf2(byte[] password, byte[] salt, int iterations, int bytes)Computes the PBKDF2 hash of a password.static booleanvalidatePassword(byte[] password, String correctHash)Validates a password using a hash.static booleanvalidatePassword(String password, String correctHash)Validates a password using a hash.
-
-
-
Field Detail
-
SALT_BYTE_SIZE
public static final int SALT_BYTE_SIZE
- See Also:
- Constant Field Values
-
DERIVED_KEY_SIZE
public static final int DERIVED_KEY_SIZE
- See Also:
- Constant Field Values
-
PBKDF2_ITERATIONS
public static final int PBKDF2_ITERATIONS
- See Also:
- Constant Field Values
-
ITERATION_INDEX
public static final int ITERATION_INDEX
- See Also:
- Constant Field Values
-
SALT_INDEX
public static final int SALT_INDEX
- See Also:
- Constant Field Values
-
PBKDF2_INDEX
public static final int PBKDF2_INDEX
- See Also:
- Constant Field Values
-
-
Method Detail
-
createHash
public static String createHash(String password)
Returns a salted PBKDF2 hash of the password.- Parameters:
password- - the password to hash- Returns:
- a salted PBKDF2 hash of the password
-
createHash
public static String createHash(byte[] password)
Returns a salted PBKDF2 hash of the password.- Parameters:
password- - the password to hash- Returns:
- a salted PBKDF2 hash of the password
-
createHash
public static String createHash(byte[] password, int saltSize, int iterations, int dkSize)
Returns a salted PBKDF2 hash of the password.- Parameters:
password- - the password to hashsaltSize- - the size of salt in bytesiterations- - the iteration count (slowness factor)dkSize- - the length of the derived key- Returns:
- a salted PBKDF2 hash of the password
-
validatePassword
public static boolean validatePassword(String password, String correctHash)
Validates a password using a hash.- Parameters:
password- - the password to checkcorrectHash- - the hash of the valid password- Returns:
- true if the password is correct, false if not
-
validatePassword
public static boolean validatePassword(byte[] password, String correctHash)Validates a password using a hash.- Parameters:
password- - the password to checkcorrectHash- - the hash of the valid password- Returns:
- true if the password is correct, false if not
-
pbkdf2
public static byte[] pbkdf2(byte[] password, byte[] salt, int iterations, int bytes)Computes the PBKDF2 hash of a password.- Parameters:
password- - the password to hash.salt- - the saltiterations- - the iteration count (slowness factor)bytes- - the length of the hash to compute in bytes- Returns:
- the PBDKF2 hash of the password
-
-