Search in sources :

Example 1 with DExportPrivateKeyPkcs8

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);
    }
}
Also used : DExportPrivateKeyPkcs8(org.kse.gui.dialogs.importexport.DExportPrivateKeyPkcs8) Pkcs8PbeType(org.kse.crypto.privatekey.Pkcs8PbeType) 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 Pkcs8PbeType (org.kse.crypto.privatekey.Pkcs8PbeType)1 DExportPrivateKeyPkcs8 (org.kse.gui.dialogs.importexport.DExportPrivateKeyPkcs8)1