I'm trying to write a password hashing function using PBKDF2 and Bouncy Castle as the provider. I'm new to cryptography, so the majority of the code below was taken from another SO post. However, every time I run the function for a given password, it produces the same hash. Shouldn't the hash be different, considering I'm generating a new salt each time from the Secure Random object? Here is the code:
SecureRandom random = new SecureRandom();
byte[] salt = new byte[8];
final int iterationCount = 20000;
final int keyLength = 256;
random.nextBytes(salt);
try {
SecretKeyFactory factoryBC = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA3-256", "BC");
KeySpec keySpecBC = new PBEKeySpec(password.toCharArray(), salt, iterationCount, keyLength);
SecretKey keyBC = factoryBC.generateSecret(keySpecBC);
String hashedPW = keyBC.getEncoded().toString();
}
For example, if I pass in the string "hello", I will get back "[B@44af588b" each time.