I was experimenting with key derivation functions and I noticed that the secret keys I generate via all the PBE algorithms encode to the plain text password.
With that I mean that:
public class Main {
public static void main(String[] args) throws Exception {
byte[] salt = new byte[256/8];
SecureRandom.getInstanceStrong().nextBytes(salt);
KeySpec spec = new PBEKeySpec("password".toCharArray(), salt, /*iterations*/ 1000, /*key length*/ 1024);
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBEWithHMACSHA512AndAES_256"); // PBE with HMAC SHA512 and AES_256
SecretKey secret = factory.generateSecret(spec);
System.out.println(new String(secret.getEncoded()));
}
}
prints password
where I expected 1024 seemingly-random bytes. This doesn't quite add up for me.. can you explain it?
BTW: Note the same code does seem to work as I expect with PBKDF2 algorithms.
PS: In case it matters, I'm using vanilla OpenJDK 13 on mac (13.0.1.hs-adpt)