Search in sources :

Example 1 with DExportPrivateKeyPvk

use of org.kse.gui.dialogs.importexport.DExportPrivateKeyPvk in project keystore-explorer by kaikramer.

the class ExportKeyPairPrivateKeyAction method exportAsPvk.

private void exportAsPvk(PrivateKey privateKey, String alias) throws CryptoException, IOException {
    File exportFile = null;
    try {
        DExportPrivateKeyPvk dExportPrivateKeyPvk = new DExportPrivateKeyPvk(frame, alias, privateKey, applicationSettings.getPasswordQualityConfig());
        dExportPrivateKeyPvk.setLocationRelativeTo(frame);
        dExportPrivateKeyPvk.setVisible(true);
        if (!dExportPrivateKeyPvk.exportSelected()) {
            return;
        }
        exportFile = dExportPrivateKeyPvk.getExportFile();
        int keyType = dExportPrivateKeyPvk.getKeyType();
        boolean encrypt = dExportPrivateKeyPvk.encrypt();
        boolean strongEncryption = false;
        Password exportPassword = null;
        if (encrypt) {
            strongEncryption = dExportPrivateKeyPvk.useStrongEncryption();
            exportPassword = dExportPrivateKeyPvk.getExportPassword();
        }
        byte[] encoded = getPvkEncodedPrivateKey(privateKey, keyType, exportPassword, strongEncryption);
        exportEncodedPrivateKey(encoded, exportFile);
        JOptionPane.showMessageDialog(frame, res.getString("ExportKeyPairPrivateKeyAction.ExportPrivateKeyPvkSuccessful.message"), res.getString("ExportKeyPairPrivateKeyAction.ExportPrivateKeyPvk.Title"), JOptionPane.INFORMATION_MESSAGE);
    } catch (FileNotFoundException ex) {
        String message = MessageFormat.format(res.getString("ExportKeyPairPrivateKeyAction.NoWriteFile.message"), exportFile);
        JOptionPane.showMessageDialog(frame, message, res.getString("ExportKeyPairPrivateKeyAction.ExportPrivateKeyPvk.Title"), JOptionPane.WARNING_MESSAGE);
    }
}
Also used : DExportPrivateKeyPvk(org.kse.gui.dialogs.importexport.DExportPrivateKeyPvk) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) Password(org.kse.crypto.Password)

Aggregations

File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 Password (org.kse.crypto.Password)1 DExportPrivateKeyPvk (org.kse.gui.dialogs.importexport.DExportPrivateKeyPvk)1