@Test
public void testKeyInProtectedKeyStore() throws Exception {

    String password = "pa$$w0rd";
    
    // Build a key-store from properties which we then serialise and read in.
    Properties options = new Properties();
    options.setProperty("security.publickey.test", encoded);
    KeyStoreBuilder builder = new KeyStoreBuilder(options, nullOpener);
    KeyStore source = builder.buildKeyStore();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    source.store(os, password.toCharArray());
    ResourceOpener opener = new ConstantOpener(new ByteArrayInputStream(os.toByteArray()));
    
    options = new Properties();
    options.setProperty("security.keystore.password", password);
    builder = new KeyStoreBuilder(options, opener);
    KeyStore store = builder.buildKeyStore();
    
    Certificate cert = store.getCertificate("test");
    assertNotNull("Could not find certificate", cert);
    assertEquals(key, cert.getPublicKey());
}