I'm trying to encrypt a payload starting from a password using Bouncy Castle 1.58 (org.bouncycastle:bcprov-jdk15on:1.58):

```
import org.bouncycastle.jce.provider.BouncyCastleProvider;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.PBEParameterSpec;
import java.security.SecureRandom;
import java.security.Security;

public class Scratch {
    public static void main(String[] args) throws Exception {
        int keyLength = 128;

        Security.addProvider(new BouncyCastleProvider());

        String password = "password";

        SecureRandom randomGenerator = new SecureRandom();
        byte[] salt = randomGenerator.generateSeed(128 / 8);
        PBEKeySpec keySpec = new PBEKeySpec(password.toCharArray(), salt, 872791, keyLength);
        SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA512");
        SecretKey passwordKey = secretKeyFactory.generateSecret(keySpec);
        System.out.println("passwordKey: " + passwordKey);
        System.out.println("passwordKey.getEncoded(): " + Arrays.toString(passwordKey.getEncoded()));
        System.out.println("passwordKey.getEncoded().length: " + passwordKey.getEncoded().length);
        System.out.println("passwordKey.getFormat():" + passwordKey.getFormat());
        System.out.println("passwordKey.getAlgorithm(): " + passwordKey.getAlgorithm());

        Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", "BC");
        PBEParameterSpec parSpec = new PBEParameterSpec(salt, 872791);
        cipher.init(Cipher.ENCRYPT_MODE, passwordKey, parSpec);
    }
}

```

and this is the error I get:

```
Exception in thread "main" org.bouncycastle.jcajce.provider.symmetric.util.BaseBlockCipher$InvalidKeyOrParametersException: Key length not 128/192/256 bits.
    at org.bouncycastle.jcajce.provider.symmetric.util.BaseBlockCipher.engineInit(Unknown Source)
    at javax.crypto.Cipher.init(Cipher.java:1394)
    at javax.crypto.Cipher.init(Cipher.java:1327)
    at tech.dashman.dashman.Scratch.main(Scratch.java:30)
Caused by: java.lang.IllegalArgumentException: Key length not 128/192/256 bits.
    at org.bouncycastle.crypto.engines.AESEngine.generateWorkingKey(Unknown Source)
    at org.bouncycastle.crypto.engines.AESEngine.init(Unknown Source)
    at org.bouncycastle.crypto.modes.GCMBlockCipher.init(Unknown Source)
    at org.bouncycastle.jcajce.provider.symmetric.util.BaseBlockCipher$AEADGenericBlockCipher.init(Unknown Source)
    ... 4 more

```

and the debugging output looks like this:

```
passwordKey: com.sun.crypto.provider.PBKDF2KeyImpl@f00a68fe
passwordKey.getEncoded(): [122, -75, -99, 114, -123, 71, 6, 50, 45, 64, -97, 10, -66, 7, 110, 17]
passwordKey.getEncoded().length: 16
passwordKey.getFormat():RAW
passwordKey.getAlgorithm(): PBKDF2WithHmacSHA512

```

What am I missing?