@Test public void generateHashTest() { char[][] password = new char[5][]; for (int i = 0; i < password.length; i++) { password[i] = randomString(20).toCharArray(); byte[] salt = PasswordUtil.generateRandomSalt(); logger.debug("Tested Password: {}.", String.valueOf(password[i])); byte[] hash = PasswordUtil.generateHash(password[i], salt); assertNotNull(hash); assertTrue(hash.length == PasswordUtil.HASH_BIT_SIZE / 8); logger.debug("Generated Salt: {}.", EncryptionUtil.byteToHex(hash)); for (int j = 0; j < 5; j++) { assertTrue(Arrays.equals(hash, PasswordUtil.generateHash(password[i], salt))); } for (int j = 0; j < 5; j++) { char[] otherPW; do { otherPW = randomString(20).toCharArray(); } while (Arrays.equals(otherPW, password[i])); byte[] otherSalt; do { otherSalt = PasswordUtil.generateRandomSalt(); } while (Arrays.equals(otherSalt, salt)); assertFalse(Arrays.equals(hash, PasswordUtil.generateHash(password[i], otherSalt))); assertFalse(Arrays.equals(hash, PasswordUtil.generateHash(otherPW, salt))); assertFalse(Arrays.equals(hash, PasswordUtil.generateHash(otherPW, otherSalt))); } } }
public static byte[] generateHash(char[] password, byte[] salt) { return getPBKDF2Hash(password, salt, HASH_BIT_SIZE); }
PasswordUtil { public static byte[] generateHash(char[] password, byte[] salt) { return getPBKDF2Hash(password, salt, HASH_BIT_SIZE); } }
PasswordUtil { public static byte[] generateHash(char[] password, byte[] salt) { return getPBKDF2Hash(password, salt, HASH_BIT_SIZE); } private  PasswordUtil(); }
PasswordUtil { public static byte[] generateHash(char[] password, byte[] salt) { return getPBKDF2Hash(password, salt, HASH_BIT_SIZE); } private  PasswordUtil(); static byte[] generateRandomSalt(); static byte[] generateFixedSalt(byte[] input); static byte[] generateHash(char[] password, byte[] salt); static SecretKey generateAESKeyFromPassword(String password, String pin, AES_KEYLENGTH keyLength); static boolean validatePassword(char[] password, byte[] salt, byte[] correctHash); }
PasswordUtil { public static byte[] generateHash(char[] password, byte[] salt) { return getPBKDF2Hash(password, salt, HASH_BIT_SIZE); } private  PasswordUtil(); static byte[] generateRandomSalt(); static byte[] generateFixedSalt(byte[] input); static byte[] generateHash(char[] password, byte[] salt); static SecretKey generateAESKeyFromPassword(String password, String pin, AES_KEYLENGTH keyLength); static boolean validatePassword(char[] password, byte[] salt, byte[] correctHash); static final int HASH_BIT_SIZE; static final int SALT_BIT_SIZE; }