public static String createHash ( char [ ] password ) throws NoSuchAlgorithmException , InvalidKeySpecException { // 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 ) ; // format iterations:salt:hash return PBKDF2_ITERATIONS + ":" + toHex ( salt ) + ":" + toHex ( hash ) ; }
Returns a salted PBKDF2 hash of the password .