@Test
public void readEncryptedPemPrivateKey() throws Exception {

    // encrypted private key
    Path path = Paths.get(getClass().getResource("/ssl/server-with-pass.p8").toURI());
    PrivateKey privateKey = PrivateKeyReader.fromPem(path, "password");
    assertNotNull(privateKey);
    assertEquals("PKCS#8", privateKey.getFormat());
    try {
        PrivateKeyReader.fromPem(path, null);
        fail("Should fail with null password");
    } catch (Exception ex) {
    }
    try {
        PrivateKeyReader.fromPem(path, "");
        fail("Should fail with empty password");
    } catch (Exception ex) {
    }
    try {
        PrivateKeyReader.fromPem(path, "wrong-password");
        fail("Should fail with wrong password");
    } catch (Exception ex) {
    }
}