use of org.kse.gui.dialogs.importexport.DExportPrivateKeyOpenSsl in project keystore-explorer by kaikramer.
the class ExportKeyPairPrivateKeyAction method exportAsOpenSsl.
private void exportAsOpenSsl(PrivateKey privateKey, String alias) throws CryptoException, IOException {
File exportFile = null;
try {
DExportPrivateKeyOpenSsl dExportPrivateKeyOpenSsl = new DExportPrivateKeyOpenSsl(frame, alias, applicationSettings.getPasswordQualityConfig());
dExportPrivateKeyOpenSsl.setLocationRelativeTo(frame);
dExportPrivateKeyOpenSsl.setVisible(true);
if (!dExportPrivateKeyOpenSsl.exportSelected()) {
return;
}
exportFile = dExportPrivateKeyOpenSsl.getExportFile();
boolean pemEncode = dExportPrivateKeyOpenSsl.pemEncode();
boolean encrypt = dExportPrivateKeyOpenSsl.encrypt();
OpenSslPbeType pbeAlgorithm = null;
Password exportPassword = null;
if (encrypt) {
pbeAlgorithm = dExportPrivateKeyOpenSsl.getPbeAlgorithm();
exportPassword = dExportPrivateKeyOpenSsl.getExportPassword();
}
byte[] encoded = getOpenSslEncodedPrivateKey(privateKey, pemEncode, pbeAlgorithm, exportPassword);
exportEncodedPrivateKey(encoded, exportFile);
JOptionPane.showMessageDialog(frame, res.getString("ExportKeyPairPrivateKeyAction.ExportPrivateKeyOpenSslSuccessful.message"), res.getString("ExportKeyPairPrivateKeyAction.ExportPrivateKeyOpenSsl.Title"), JOptionPane.INFORMATION_MESSAGE);
} catch (FileNotFoundException ex) {
String message = MessageFormat.format(res.getString("ExportKeyPairPrivateKeyAction.NoWriteFile.message"), exportFile);
JOptionPane.showMessageDialog(frame, message, res.getString("ExportKeyPairPrivateKeyAction.ExportPrivateKeyOpenSsl.Title"), JOptionPane.WARNING_MESSAGE);
}
}
Aggregations