use of org.kse.gui.dialogs.importexport.DExportKeyPair in project keystore-explorer by kaikramer.
the class ExportKeyPairAction method doAction.
/**
* Do action.
*/
@Override
protected void doAction() {
File exportFile = null;
try {
KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
KeyStoreState currentState = history.getCurrentState();
String alias = kseFrame.getSelectedEntryAlias();
Password password = getEntryPassword(alias, currentState);
if (password == null) {
return;
}
KeyStore keyStore = currentState.getKeyStore();
PrivateKey privateKey = (PrivateKey) keyStore.getKey(alias, password.toCharArray());
Certificate[] certificates = keyStore.getCertificateChain(alias);
DExportKeyPair dExportKeyPair = new DExportKeyPair(frame, alias, applicationSettings.getPasswordQualityConfig());
dExportKeyPair.setLocationRelativeTo(frame);
dExportKeyPair.setVisible(true);
if (!dExportKeyPair.exportSelected()) {
return;
}
exportFile = dExportKeyPair.getExportFile();
Password exportPassword = dExportKeyPair.getExportPassword();
KeyStore pkcs12 = KeyStoreUtil.create(KeyStoreType.PKCS12);
certificates = X509CertUtil.orderX509CertChain(X509CertUtil.convertCertificates(certificates));
pkcs12.setKeyEntry(alias, privateKey, exportPassword.toCharArray(), certificates);
KeyStoreUtil.save(pkcs12, exportFile, exportPassword);
JOptionPane.showMessageDialog(frame, res.getString("ExportKeyPairAction.ExportKeyPairSuccessful.message"), res.getString("ExportKeyPairAction.ExportKeyPair.Title"), JOptionPane.INFORMATION_MESSAGE);
} catch (FileNotFoundException ex) {
String message = MessageFormat.format(res.getString("ExportKeyPairAction.NoWriteFile.message"), exportFile);
JOptionPane.showMessageDialog(frame, message, res.getString("ExportKeyPairAction.ExportKeyPair.Title"), JOptionPane.WARNING_MESSAGE);
} catch (Exception ex) {
DError.displayError(frame, ex);
}
}
Aggregations