Search in sources :

Example 1 with DViewPrivateKey

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

the class ExamineFileAction method openPrivateKey.

private void openPrivateKey(File file, CryptoFileType fileType) throws IOException, CryptoException {
    PrivateKey privKey = null;
    Password password = null;
    switch(fileType) {
        case ENC_PKCS8_PVK:
            password = getPassword(file);
            if (password == null || password.isNulled()) {
                return;
            }
            privKey = Pkcs8Util.loadEncrypted(new FileInputStream(file), password);
            break;
        case UNENC_PKCS8_PVK:
            privKey = Pkcs8Util.load(new FileInputStream(file));
            break;
        case ENC_OPENSSL_PVK:
            password = getPassword(file);
            if (password == null || password.isNulled()) {
                return;
            }
            privKey = OpenSslPvkUtil.loadEncrypted(new FileInputStream(file), password);
            break;
        case UNENC_OPENSSL_PVK:
            privKey = OpenSslPvkUtil.load(new FileInputStream(file));
            break;
        case ENC_MS_PVK:
            password = getPassword(file);
            if (password == null || password.isNulled()) {
                return;
            }
            privKey = MsPvkUtil.loadEncrypted(new FileInputStream(file), password);
            break;
        case UNENC_MS_PVK:
            privKey = MsPvkUtil.load(new FileInputStream(file));
            break;
        default:
            break;
    }
    DViewPrivateKey dViewPrivateKey = new DViewPrivateKey(frame, MessageFormat.format(res.getString("ExamineFileAction.PrivateKeyDetailsFile.Title"), file.getName()), privKey, null);
    dViewPrivateKey.setLocationRelativeTo(frame);
    dViewPrivateKey.setVisible(true);
}
Also used : DViewPrivateKey(org.kse.gui.dialogs.DViewPrivateKey) PrivateKey(java.security.PrivateKey) DViewPrivateKey(org.kse.gui.dialogs.DViewPrivateKey) FileInputStream(java.io.FileInputStream) DGetPassword(org.kse.gui.password.DGetPassword) Password(org.kse.crypto.Password)

Example 2 with DViewPrivateKey

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

the class KeyDetailsAction method showKeySelectedEntry.

/**
 * Show the key details of the selected KeyStore entry.
 */
public void showKeySelectedEntry() {
    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();
        Key key = keyStore.getKey(alias, password.toCharArray());
        if (key instanceof SecretKey) {
            SecretKey secretKey = (SecretKey) key;
            DViewSecretKey dViewSecretKey = new DViewSecretKey(frame, MessageFormat.format(res.getString("KeyDetailsAction.SecretKeyDetailsEntry.Title"), alias), secretKey);
            dViewSecretKey.setLocationRelativeTo(frame);
            dViewSecretKey.setVisible(true);
        } else if (key instanceof PrivateKey) {
            PrivateKey privateKey = (PrivateKey) key;
            DViewPrivateKey dViewPrivateKey = new DViewPrivateKey(frame, MessageFormat.format(res.getString("KeyDetailsAction.PrivateKeyDetailsEntry.Title"), alias), privateKey, history.getExplicitProvider());
            dViewPrivateKey.setLocationRelativeTo(frame);
            dViewPrivateKey.setVisible(true);
        } else if (key instanceof PublicKey) {
            PublicKey publicKey = (PublicKey) key;
            DViewPublicKey dViewPublicKey = new DViewPublicKey(frame, MessageFormat.format(res.getString("KeyDetailsAction.PublicKeyDetailsEntry.Title"), alias), publicKey);
            dViewPublicKey.setLocationRelativeTo(frame);
            dViewPublicKey.setVisible(true);
        }
    } catch (Exception ex) {
        DError.displayError(frame, ex);
    }
}
Also used : KeyStoreState(org.kse.utilities.history.KeyStoreState) KeyStoreHistory(org.kse.utilities.history.KeyStoreHistory) DViewSecretKey(org.kse.gui.dialogs.DViewSecretKey) PrivateKey(java.security.PrivateKey) DViewPrivateKey(org.kse.gui.dialogs.DViewPrivateKey) PublicKey(java.security.PublicKey) DViewPublicKey(org.kse.gui.dialogs.DViewPublicKey) DViewPrivateKey(org.kse.gui.dialogs.DViewPrivateKey) KeyStore(java.security.KeyStore) DViewSecretKey(org.kse.gui.dialogs.DViewSecretKey) SecretKey(javax.crypto.SecretKey) DViewPublicKey(org.kse.gui.dialogs.DViewPublicKey) DViewSecretKey(org.kse.gui.dialogs.DViewSecretKey) PublicKey(java.security.PublicKey) DViewPublicKey(org.kse.gui.dialogs.DViewPublicKey) Key(java.security.Key) PrivateKey(java.security.PrivateKey) SecretKey(javax.crypto.SecretKey) DViewPrivateKey(org.kse.gui.dialogs.DViewPrivateKey) Password(org.kse.crypto.Password)

Example 3 with DViewPrivateKey

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

the class KeyPairPrivateKeyDetailsAction 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 privKey = (PrivateKey) keyStore.getKey(alias, password.toCharArray());
        DViewPrivateKey dViewPrivateKey = new DViewPrivateKey(frame, MessageFormat.format(res.getString("KeyPairPrivateKeyDetailsAction.PrivKeyDetailsEntry.Title"), alias), privKey, history.getExplicitProvider());
        dViewPrivateKey.setLocationRelativeTo(frame);
        dViewPrivateKey.setVisible(true);
    } catch (Exception ex) {
        DError.displayError(frame, ex);
    }
}
Also used : KeyStoreState(org.kse.utilities.history.KeyStoreState) KeyStoreHistory(org.kse.utilities.history.KeyStoreHistory) PrivateKey(java.security.PrivateKey) DViewPrivateKey(org.kse.gui.dialogs.DViewPrivateKey) DViewPrivateKey(org.kse.gui.dialogs.DViewPrivateKey) KeyStore(java.security.KeyStore) Password(org.kse.crypto.Password)

Example 4 with DViewPrivateKey

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

the class DImportKeyPairOpenSsl method privateKeyDetailsPressed.

private void privateKeyDetailsPressed() {
    try {
        String path = new File(jtfPrivateKeyPath.getText()).getName();
        PrivateKey privateKey = loadPrivateKey();
        if (privateKey != null) {
            DViewPrivateKey dViewPrivateKey = new DViewPrivateKey(this, MessageFormat.format(res.getString("DImportKeyPairOpenSsl.ViewPrivateKeyDetails.Title"), path), privateKey, new BouncyCastleProvider());
            dViewPrivateKey.setLocationRelativeTo(this);
            dViewPrivateKey.setVisible(true);
        }
    } catch (CryptoException ex) {
        DError.displayError(this, ex);
    }
}
Also used : PrivateKey(java.security.PrivateKey) DViewPrivateKey(org.kse.gui.dialogs.DViewPrivateKey) DViewPrivateKey(org.kse.gui.dialogs.DViewPrivateKey) CryptoException(org.kse.crypto.CryptoException) File(java.io.File) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Example 5 with DViewPrivateKey

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

the class DImportKeyPairPkcs8 method privateKeyDetailsPressed.

private void privateKeyDetailsPressed() {
    try {
        String path = new File(jtfPrivateKeyPath.getText()).getName();
        PrivateKey privateKey = loadPrivateKey();
        if (privateKey != null) {
            DViewPrivateKey dViewPrivateKey = new DViewPrivateKey(this, MessageFormat.format(res.getString("DImportKeyPairPkcs8.ViewPrivateKeyDetails.Title"), path), privateKey, new BouncyCastleProvider());
            dViewPrivateKey.setLocationRelativeTo(this);
            dViewPrivateKey.setVisible(true);
        }
    } catch (CryptoException ex) {
        DError.displayError(this, ex);
    }
}
Also used : PrivateKey(java.security.PrivateKey) DViewPrivateKey(org.kse.gui.dialogs.DViewPrivateKey) DViewPrivateKey(org.kse.gui.dialogs.DViewPrivateKey) CryptoException(org.kse.crypto.CryptoException) File(java.io.File) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Aggregations

PrivateKey (java.security.PrivateKey)6 DViewPrivateKey (org.kse.gui.dialogs.DViewPrivateKey)6 File (java.io.File)3 BouncyCastleProvider (org.bouncycastle.jce.provider.BouncyCastleProvider)3 CryptoException (org.kse.crypto.CryptoException)3 Password (org.kse.crypto.Password)3 KeyStore (java.security.KeyStore)2 KeyStoreHistory (org.kse.utilities.history.KeyStoreHistory)2 KeyStoreState (org.kse.utilities.history.KeyStoreState)2 FileInputStream (java.io.FileInputStream)1 Key (java.security.Key)1 PublicKey (java.security.PublicKey)1 SecretKey (javax.crypto.SecretKey)1 DViewPublicKey (org.kse.gui.dialogs.DViewPublicKey)1 DViewSecretKey (org.kse.gui.dialogs.DViewSecretKey)1 DGetPassword (org.kse.gui.password.DGetPassword)1