use of com.adaptris.security.exc.CertException in project interlok by adaptris.
the class KeystoreProxyImp method importPrivateKey.
/**
* Import a private key from an inputstream, and assign it to the given alias.
* <p>
* The key is protected by the given key password
* </p>
* <p>
* The inputstream is expected to contain a PKCS12 object exported from
* Netscape Navigator / Internet Explorer
* </p>
*
* @param alias the alias of the Certificate
* @param keyPassword the password to protect the private key
* @param in InputStream containing the PKCS12 object
* @param filePassword The password protecting the PKCS12
* @throws AdaptrisSecurityException for any error
* @see #setPrivateKey(String, PrivateKey, char[], Certificate[])
*/
public void importPrivateKey(String alias, char[] keyPassword, InputStream in, char[] filePassword) throws AdaptrisSecurityException {
try {
// ,, Constants.SECURITY_PROVIDER);
KeyStore keystore = KeyStore.getInstance(Constants.KEYSTORE_PKCS12);
keystore.load(in, filePassword);
Key key = keystore.getKey(alias, keyPassword);
if (key instanceof PrivateKey) {
Certificate[] certChain = keystore.getCertificateChain(alias);
this.setPrivateKey(alias, (PrivateKey) key, keyPassword, certChain);
}
} catch (AdaptrisSecurityException e) {
throw e;
} catch (Exception e) {
throw new CertException(e.getMessage(), e);
}
}
Aggregations