use of org.kse.crypto.CryptoException in project keystore-explorer by kaikramer.
the class ExportKeyPairPublicKeyAction method getCertificateChain.
private X509Certificate[] getCertificateChain(String alias) throws CryptoException {
try {
KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
KeyStore keyStore = history.getCurrentState().getKeyStore();
X509Certificate[] certChain = X509CertUtil.convertCertificates(keyStore.getCertificateChain(alias));
return certChain;
} catch (KeyStoreException ex) {
String message = MessageFormat.format(res.getString("ExportKeyPairPublicKeyAction.NoAccessEntry.message"), alias);
throw new CryptoException(message, ex);
}
}
use of org.kse.crypto.CryptoException in project keystore-explorer by kaikramer.
the class ExportTrustedCertificateAction method getCertificate.
private X509Certificate getCertificate(String alias) throws CryptoException {
try {
KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
KeyStore keyStore = history.getCurrentState().getKeyStore();
X509Certificate cert = X509CertUtil.convertCertificate(keyStore.getCertificate(alias));
return cert;
} catch (KeyStoreException ex) {
String message = MessageFormat.format(res.getString("ExportTrustedCertificateAction.NoAccessEntry.message"), alias);
throw new CryptoException(message, ex);
}
}
use of org.kse.crypto.CryptoException in project keystore-explorer by kaikramer.
the class ExportTrustedCertificatePublicKeyAction method getPublicKey.
private PublicKey getPublicKey(String alias) throws CryptoException {
try {
KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
KeyStore keyStore = history.getCurrentState().getKeyStore();
X509Certificate cert = X509CertUtil.convertCertificate(keyStore.getCertificate(alias));
return cert.getPublicKey();
} catch (KeyStoreException ex) {
String message = MessageFormat.format(res.getString("ExportTrustedCertificatePublicKeyAction.NoAccessEntry.message"), alias);
throw new CryptoException(message, ex);
}
}
use of org.kse.crypto.CryptoException in project keystore-explorer by kaikramer.
the class X509CertUtil method loadCertificatesPkiPath.
private static X509Certificate[] loadCertificatesPkiPath(InputStream is) throws CryptoException {
try {
CertificateFactory cf = CertificateFactory.getInstance(X509_CERT_TYPE, BOUNCY_CASTLE.jce());
CertPath certPath = cf.generateCertPath(is, PKI_PATH_ENCODING);
List<? extends Certificate> certs = certPath.getCertificates();
ArrayList<X509Certificate> loadedCerts = new ArrayList<X509Certificate>();
for (Iterator<? extends Certificate> itr = certs.iterator(); itr.hasNext(); ) {
X509Certificate cert = (X509Certificate) itr.next();
if (cert != null) {
loadedCerts.add(cert);
}
}
return loadedCerts.toArray(new X509Certificate[loadedCerts.size()]);
} catch (CertificateException | NoSuchProviderException e) {
throw new CryptoException(res.getString("NoLoadPkiPath.exception.message"), e);
} finally {
IOUtils.closeQuietly(is);
}
}
use of org.kse.crypto.CryptoException in project keystore-explorer by kaikramer.
the class X509CertUtil method getCertsEncodedPkcs7.
/**
* PKCS #7 encode a number of certificates.
*
* @return The encoding
* @param certs
* The certificates
* @throws CryptoException
* If there was a problem encoding the certificates
*/
public static byte[] getCertsEncodedPkcs7(X509Certificate[] certs) throws CryptoException {
try {
ArrayList<Certificate> encodedCerts = new ArrayList<Certificate>();
Collections.addAll(encodedCerts, certs);
CertificateFactory cf = CertificateFactory.getInstance(X509_CERT_TYPE, BOUNCY_CASTLE.jce());
CertPath cp = cf.generateCertPath(encodedCerts);
return cp.getEncoded(PKCS7_ENCODING);
} catch (CertificateException | NoSuchProviderException e) {
throw new CryptoException(res.getString("NoPkcs7Encode.exception.message"), e);
}
}
Aggregations