protected static PKCS8EncodedKeySpec generateKeySpec(char[] password, byte[] key)
            throws IOException, PKCSException, OperatorCreationException {

        if (password == null || password.length == 0) {
            return new PKCS8EncodedKeySpec(key);
        }

        final PKCS8EncryptedPrivateKeyInfo privateKeyInfo = new PKCS8EncryptedPrivateKeyInfo(key);
        final InputDecryptorProvider decProv = new JceOpenSSLPKCS8DecryptorProviderBuilder().setProvider("BC").build(password);
        PrivateKeyInfo pkInfo = privateKeyInfo.decryptPrivateKeyInfo(decProv);
        PrivateKey privKey = new JcaPEMKeyConverter().setProvider("BC").getPrivateKey(pkInfo);
        return new PKCS8EncodedKeySpec(privKey.getEncoded());
    }
@Test
    public void testGenerateKeySpecFromPBE2EncryptedPrivateKey() throws Exception {
        final URL url = Resources.getResource("org/graylog2/shared/security/tls/key-enc-pbe2-sha256.p8");
        final byte[] privateKey = PemReader.readPrivateKey(Paths.get(url.toURI()));

        final PKCS8EncodedKeySpec keySpec = PemKeyStore.generateKeySpec("password".toCharArray(), privateKey);

        assertThat(keySpec.getFormat()).isEqualTo("PKCS#8");
        assertThat(keySpec.getEncoded()).isNotEmpty();
    }