I wrote a provisioning system for an HTTPS proxy. Before push a configuration file and uploading certificate and private key I do some validations. I have found a case when while a private key is validated by Java using PemReader OpenSSL doesn't validate the same file. This causes the httpd server to stop working since it's getting a wrong key.

I have made a test to reproduce it:

using openssl I have an error

```
$ openssl rsa -in wrong_key_test.key -check
unable to load Private Key
140736227525512:error:0906D064:PEM routines:PEM_read_bio:bad base64 decode:/BuildRoot/Library/Caches/com.apple.xbs/Sources/libressl/libressl-22/libressl/crypto/pem/pem_lib.c:828:

```

But when I run this junit test everything is ok. My expectation was to have an exception , have you any idea about it? Is it my validation wrong ?

This is the junit

```
package eu.ssl.test.validator;
import static org.junit.Assert.assertNotEquals;
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.security.KeyFactory;
import java.security.Security;
import java.security.interfaces.RSAPrivateKey;
import java.security.spec.PKCS8EncodedKeySpec;

import org.apache.commons.io.FileUtils;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.util.io.pem.PemObject;
import org.bouncycastle.util.io.pem.PemReader;
import org.junit.Before;
import org.junit.Test;

public class PemReaderTest {

private String privateKey;

@Before
public void setUp() throws IOException {
    this.privateKey = FileUtils.readFileToString(new File("./wrong_key_test.key"));
}

@Test
public void test() throws Exception {
    Security.addProvider(new BouncyCastleProvider());
    PemReader pemReader = new PemReader(new StringReader(this.privateKey));
    PemObject pemObject;
    try {
        pemObject = pemReader.readPemObject();
    } finally {
        pemReader.close();
    }
    KeyFactory factory = KeyFactory.getInstance("RSA");
    byte[] content = pemObject.getContent();
    PKCS8EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(content);
    RSAPrivateKey privateKey = (RSAPrivateKey) factory.generatePrivate(privKeySpec);
    String privateKeyModulus = privateKey.getModulus().toString();
    assertNotEquals("", privateKeyModulus);
}   
}

```

This is the PK

```none
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEA2lKPRVgFN8TfOhex+IJ6YMKUKeZgHZUGsJpHo/ipeYVeWUGa
jK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