@Override
 public SSLContext newContext(SSLContextType type) throws KeyStoreException {
   try {
     return SecurityUtils.createSSLContext(
         type,
         SecurityUtils.createKeyManagers(handler.getKeyStore(), configuration.getPassword()),
         SecurityUtils.createTrustManagers(handler.getKeyStore()));
   } catch (Exception e) {
     throw new KeyStoreException("Failed to create new context", e);
   }
 }
 public void set(String alias, X509Certificate certificate) throws KeyStoreException, IOException {
   handler.set(alias, certificate);
   if (saveOnChange) {
     // save the keystore
     save();
   }
 }
 @Override
 public X509Certificate[] getChain(String alias) throws KeyStoreException {
   Certificate[] chain = handler.getKeyStore().getCertificateChain(alias);
   X509Certificate[] certificates = new X509Certificate[chain.length];
   for (int i = 0; i < chain.length; i++) certificates[i] = (X509Certificate) chain[i];
   return certificates;
 }
 @Override
 public SecretKey getSecretKey(String alias) throws KeyStoreException {
   try {
     return handler.getSecretKey(alias, configuration.getKeyPasswords().get(alias));
   } catch (UnrecoverableKeyException e) {
     throw new KeyStoreException(e);
   } catch (NoSuchAlgorithmException e) {
     throw new RuntimeException(e);
   }
 }
 @Override
 public void rename(String oldAlias, String newAlias) throws KeyStoreException, IOException {
   try {
     handler.rename(oldAlias, newAlias, configuration.getKeyPasswords().get(oldAlias));
   } catch (UnrecoverableKeyException e) {
     throw new KeyStoreException(e);
   } catch (NoSuchAlgorithmException e) {
     throw new RuntimeException(e);
   }
   if (saveOnChange) {
     save();
   }
 }
 @Override
 public void set(String alias, PrivateKey privateKey, X509Certificate[] chain, String password)
     throws KeyStoreException, IOException {
   // add to keystore
   handler.set(alias, privateKey, chain, password);
   // add password to configuration
   configuration.getKeyPasswords().put(alias, password);
   if (saveOnChange) {
     // save the keystore
     save();
     // store the configuration
     configurationHandler.save(configuration);
   }
 }
 @Override
 public void set(String alias, SecretKey secretKey, String password)
     throws KeyStoreException, IOException {
   // add to keystore
   handler.set(alias, secretKey, password);
   // add password to configuration
   configuration.getKeyPasswords().put(alias, password);
   if (saveOnChange) {
     // save the keystore
     save();
     // store the configuration
     configurationHandler.save(configuration);
   }
 }
 @Override
 public void delete(String alias) throws KeyStoreException, IOException {
   handler.delete(alias);
   if (saveOnChange) {
     save();
   }
   // check if there was a password for this alias, delete it if necessary
   if (configuration.getKeyPasswords().containsKey(alias)) {
     configuration.getKeyPasswords().remove(alias);
     if (saveOnChange) {
       configurationHandler.save(configuration);
     }
   }
 }
 public void save(Resource resource) throws IOException {
   if (resource instanceof WritableResource) {
     WritableContainer<ByteBuffer> output = ((WritableResource) resource).getWritable();
     try {
       try {
         handler.save(IOUtils.toOutputStream(output), configuration.getPassword());
       } finally {
         output.close();
       }
     } catch (KeyStoreException e) {
       throw new RuntimeException(e);
     } catch (NoSuchAlgorithmException e) {
       throw new RuntimeException(e);
     } catch (CertificateException e) {
       throw new RuntimeException(e);
     }
   }
 }
 @Override
 public KeyStore getKeyStore() {
   return handler.getKeyStore();
 }
 @Override
 public X509Certificate getCertificate(String alias) throws KeyStoreException {
   return handler.getCertificate(alias);
 }