title: Bouncycastle can't generate private key - Unknown KeySpec type: java.security.spec.X509EncodedKeySpec
body: <p>I can't generate private key with bouncycastle due to Unknown KeySpec type: java.security.spec.X509EncodedKeySpec. (However doing same for public key doesn't throw exception and works - why?)</p>
  
  <blockquote>
    <p>java.security.spec.InvalidKeySpecException: Unknown KeySpec type:
    java.security.spec.X509EncodedKeySpec     at
    org.bouncycastle.jcajce.provider.asymmetric.rsa.KeyFactorySpi.engineGeneratePrivate(Unknown
    Source)   at
    java.security.KeyFactory.generatePrivate(KeyFactory.java:366)</p>
  </blockquote>
  
  <pre><code>        PemReader pemReader = new PemReader(new InputStreamReader(new FileInputStream("private_unencrypted.pem")));
          PemObject pemObject = pemReader.readPemObject();
          pemReader.close();
  
          KeyFactory keyFactory = KeyFactory.getInstance("RSA", "BC");
          byte[] privateKeyBytes = pemObject.getContent();
          X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(privateKeyBytes);
          PrivateKey privateKey = keyFactory.generatePrivate(x509KeySpec);
  </code></pre>