Class PasswordHash


  • public class PasswordHash
    extends Object
    PBKDF2 salted password hashing.
    Author:
    havoc AT defuse.ca, www: http://crackstation.net/hashing-security.htm
    • 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 hash
        saltSize - - the size of salt in bytes
        iterations - - 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 check
        correctHash - - 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 check
        correctHash - - 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 salt
        iterations - - the iteration count (slowness factor)
        bytes - - the length of the hash to compute in bytes
        Returns:
        the PBDKF2 hash of the password