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