Search in sources :

Example 6 with KeystoreException

use of com.adaptris.security.exc.KeystoreException in project interlok by adaptris.

the class CompositeKeystore method getPrivateKey.

/**
 * @see KeystoreProxy#getPrivateKey(String, char[])
 */
public PrivateKey getPrivateKey(String alias, char[] password) throws AdaptrisSecurityException {
    PrivateKey pk = null;
    if (aliasCache == null) {
        load();
    }
    if (!containsAlias(alias)) {
        return null;
    }
    String lca = alias.toLowerCase();
    AliasListEntry kk = aliasCache.get(lca);
    if (kk != null) {
        if (password == null) {
            logR.trace("No private key password passed as parameter, " + "using keystore password as key password");
        }
        try {
            char[] pw = password == null ? kk.getLocation().getKeystorePassword() : password;
            pk = kk.getProxy().getPrivateKey(lca, pw);
        } catch (Exception e) {
            if (AdaptrisSecurityException.class.isAssignableFrom(e.getClass())) {
                throw (AdaptrisSecurityException) e;
            } else {
                throw new KeystoreException(e);
            }
        }
    }
    return pk;
}
Also used : PrivateKey(java.security.PrivateKey) AdaptrisSecurityException(com.adaptris.security.exc.AdaptrisSecurityException) KeystoreException(com.adaptris.security.exc.KeystoreException) KeystoreException(com.adaptris.security.exc.KeystoreException) IOException(java.io.IOException) AdaptrisSecurityException(com.adaptris.security.exc.AdaptrisSecurityException) GeneralSecurityException(java.security.GeneralSecurityException)

Aggregations

KeystoreException (com.adaptris.security.exc.KeystoreException)6 KeystoreProxy (com.adaptris.security.keystore.KeystoreProxy)3 AdaptrisSecurityException (com.adaptris.security.exc.AdaptrisSecurityException)2 ConfiguredKeystore (com.adaptris.security.keystore.ConfiguredKeystore)2 IOException (java.io.IOException)2 GeneralSecurityException (java.security.GeneralSecurityException)2 PrivateKey (java.security.PrivateKey)2 Certificate (java.security.cert.Certificate)2 Map (java.util.Map)2 CertException (com.adaptris.security.exc.CertException)1 DecryptException (com.adaptris.security.exc.DecryptException)1 EncryptException (com.adaptris.security.exc.EncryptException)1 VerifyException (com.adaptris.security.exc.VerifyException)1 KeyStore (java.security.KeyStore)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 NoSuchProviderException (java.security.NoSuchProviderException)1