Search in sources :

Example 1 with DExportPrivateKeyType

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

the class ExportKeyPairPrivateKeyAction method doAction.

/**
 * Do action.
 */
@Override
protected void doAction() {
    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());
        DExportPrivateKeyType dExportPrivateKeyType = new DExportPrivateKeyType(frame);
        dExportPrivateKeyType.setLocationRelativeTo(frame);
        dExportPrivateKeyType.setVisible(true);
        if (!dExportPrivateKeyType.exportTypeSelected()) {
            return;
        }
        if (dExportPrivateKeyType.exportPkcs8()) {
            exportAsPkcs8(privateKey, alias);
        } else if (dExportPrivateKeyType.exportPvk()) {
            exportAsPvk(privateKey, alias);
        } else {
            exportAsOpenSsl(privateKey, alias);
        }
    } catch (Exception ex) {
        DError.displayError(frame, ex);
    }
}
Also used : KeyStoreState(org.kse.utilities.history.KeyStoreState) KeyStoreHistory(org.kse.utilities.history.KeyStoreHistory) DSAPrivateKey(java.security.interfaces.DSAPrivateKey) PrivateKey(java.security.PrivateKey) DExportPrivateKeyType(org.kse.gui.dialogs.importexport.DExportPrivateKeyType) KeyStore(java.security.KeyStore) CryptoException(org.kse.crypto.CryptoException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Password(org.kse.crypto.Password)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 KeyStore (java.security.KeyStore)1 PrivateKey (java.security.PrivateKey)1 DSAPrivateKey (java.security.interfaces.DSAPrivateKey)1 CryptoException (org.kse.crypto.CryptoException)1 Password (org.kse.crypto.Password)1 DExportPrivateKeyType (org.kse.gui.dialogs.importexport.DExportPrivateKeyType)1 KeyStoreHistory (org.kse.utilities.history.KeyStoreHistory)1 KeyStoreState (org.kse.utilities.history.KeyStoreState)1