Search in sources :

Example 1 with PrivateKeyEncryptedException

use of org.kse.crypto.privatekey.PrivateKeyEncryptedException in project keystore-explorer by kaikramer.

the class DImportKeyPairPkcs8 method loadPrivateKey.

private PrivateKey loadPrivateKey() {
    String privateKeyPath = jtfPrivateKeyPath.getText().trim();
    if (privateKeyPath.length() == 0) {
        JOptionPane.showMessageDialog(this, res.getString("DImportKeyPairPkcs8.PrivateKeyRequired.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
        return null;
    }
    File privateKeyFile = new File(privateKeyPath);
    try {
        PrivateKey privateKey = null;
        if (!jcbEncrypted.isSelected()) {
            privateKey = Pkcs8Util.load(new FileInputStream(privateKeyFile));
        } else {
            Password password = new Password(jpfPassword.getPassword());
            privateKey = Pkcs8Util.loadEncrypted(new FileInputStream(privateKeyFile), password);
        }
        return privateKey;
    } catch (PrivateKeyEncryptedException ex) {
        JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairPkcs8.PrivateKeyEncrypted.message"), privateKeyFile), getTitle(), JOptionPane.WARNING_MESSAGE);
        jcbEncrypted.setSelected(true);
        return null;
    } catch (PrivateKeyUnencryptedException ex) {
        JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairPkcs8.PrivateKeyNotEncrypted.message"), privateKeyFile), getTitle(), JOptionPane.WARNING_MESSAGE);
        jcbEncrypted.setSelected(false);
        return null;
    } catch (PrivateKeyPbeNotSupportedException ex) {
        JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairPkcs8.PrivateKeyPbeNotSupported.message"), ex.getUnsupportedPbe()), getTitle(), JOptionPane.WARNING_MESSAGE);
        return null;
    } catch (FileNotFoundException ex) {
        JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairPkcs8.NoReadFile.message"), privateKeyFile), getTitle(), JOptionPane.WARNING_MESSAGE);
        return null;
    } catch (Exception ex) {
        Problem problem = createLoadPkcs8Problem(ex, privateKeyFile);
        DProblem dProblem = new DProblem(this, res.getString("DImportKeyPairPkcs8.ProblemLoadingPkcs8.Title"), problem);
        dProblem.setLocationRelativeTo(this);
        dProblem.setVisible(true);
        return null;
    }
}
Also used : PrivateKeyEncryptedException(org.kse.crypto.privatekey.PrivateKeyEncryptedException) PrivateKeyUnencryptedException(org.kse.crypto.privatekey.PrivateKeyUnencryptedException) PrivateKey(java.security.PrivateKey) DViewPrivateKey(org.kse.gui.dialogs.DViewPrivateKey) FileNotFoundException(java.io.FileNotFoundException) PrivateKeyPbeNotSupportedException(org.kse.crypto.privatekey.PrivateKeyPbeNotSupportedException) Problem(org.kse.gui.error.Problem) DProblem(org.kse.gui.error.DProblem) File(java.io.File) FileInputStream(java.io.FileInputStream) CryptoException(org.kse.crypto.CryptoException) PrivateKeyUnencryptedException(org.kse.crypto.privatekey.PrivateKeyUnencryptedException) PrivateKeyPbeNotSupportedException(org.kse.crypto.privatekey.PrivateKeyPbeNotSupportedException) FileNotFoundException(java.io.FileNotFoundException) PrivateKeyEncryptedException(org.kse.crypto.privatekey.PrivateKeyEncryptedException) DProblem(org.kse.gui.error.DProblem) Password(org.kse.crypto.Password)

Example 2 with PrivateKeyEncryptedException

use of org.kse.crypto.privatekey.PrivateKeyEncryptedException in project keystore-explorer by kaikramer.

the class DImportKeyPairOpenSsl method loadPrivateKey.

private PrivateKey loadPrivateKey() {
    String privateKeyPath = jtfPrivateKeyPath.getText().trim();
    if (privateKeyPath.length() == 0) {
        JOptionPane.showMessageDialog(this, res.getString("DImportKeyPairOpenSsl.PrivateKeyRequired.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
        return null;
    }
    File privateKeyFile = new File(privateKeyPath);
    try {
        PrivateKey privateKey = null;
        if (!jcbEncrypted.isSelected()) {
            privateKey = OpenSslPvkUtil.load(new FileInputStream(privateKeyFile));
        } else {
            Password password = new Password(jpfPassword.getPassword());
            privateKey = OpenSslPvkUtil.loadEncrypted(new FileInputStream(privateKeyFile), password);
        }
        return privateKey;
    } catch (PrivateKeyEncryptedException ex) {
        JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairOpenSsl.PrivateKeyEncrypted.message"), privateKeyFile), getTitle(), JOptionPane.WARNING_MESSAGE);
        jcbEncrypted.setSelected(true);
        return null;
    } catch (PrivateKeyUnencryptedException ex) {
        JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairOpenSsl.PrivateKeyNotEncrypted.message"), privateKeyFile), getTitle(), JOptionPane.WARNING_MESSAGE);
        jcbEncrypted.setSelected(false);
        return null;
    } catch (PrivateKeyPbeNotSupportedException ex) {
        JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairOpenSsl.PrivateKeyPbeNotSupported.message"), ex.getUnsupportedPbe()), getTitle(), JOptionPane.WARNING_MESSAGE);
        return null;
    } catch (FileNotFoundException ex) {
        JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairOpenSsl.NoReadFile.message"), privateKeyFile), getTitle(), JOptionPane.WARNING_MESSAGE);
        return null;
    } catch (Exception ex) {
        Problem problem = createLoadOpenSslProblem(ex, privateKeyFile);
        DProblem dProblem = new DProblem(this, res.getString("DImportKeyPairOpenSsl.ProblemLoadingOpenSsl.Title"), problem);
        dProblem.setLocationRelativeTo(this);
        dProblem.setVisible(true);
        return null;
    }
}
Also used : PrivateKeyEncryptedException(org.kse.crypto.privatekey.PrivateKeyEncryptedException) PrivateKeyUnencryptedException(org.kse.crypto.privatekey.PrivateKeyUnencryptedException) PrivateKey(java.security.PrivateKey) DViewPrivateKey(org.kse.gui.dialogs.DViewPrivateKey) FileNotFoundException(java.io.FileNotFoundException) PrivateKeyPbeNotSupportedException(org.kse.crypto.privatekey.PrivateKeyPbeNotSupportedException) Problem(org.kse.gui.error.Problem) DProblem(org.kse.gui.error.DProblem) File(java.io.File) FileInputStream(java.io.FileInputStream) CryptoException(org.kse.crypto.CryptoException) PrivateKeyUnencryptedException(org.kse.crypto.privatekey.PrivateKeyUnencryptedException) PrivateKeyPbeNotSupportedException(org.kse.crypto.privatekey.PrivateKeyPbeNotSupportedException) FileNotFoundException(java.io.FileNotFoundException) PrivateKeyEncryptedException(org.kse.crypto.privatekey.PrivateKeyEncryptedException) DProblem(org.kse.gui.error.DProblem) Password(org.kse.crypto.Password)

Example 3 with PrivateKeyEncryptedException

use of org.kse.crypto.privatekey.PrivateKeyEncryptedException in project keystore-explorer by kaikramer.

the class DImportKeyPairPvk method loadPrivateKey.

private PrivateKey loadPrivateKey() {
    String privateKeyPath = jtfPrivateKeyPath.getText().trim();
    if (privateKeyPath.length() == 0) {
        JOptionPane.showMessageDialog(this, res.getString("DImportKeyPairPvk.PrivateKeyRequired.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
        return null;
    }
    File privateKeyFile = new File(privateKeyPath);
    try {
        PrivateKey privateKey = null;
        if (!jcbEncrypted.isSelected()) {
            privateKey = MsPvkUtil.load(new FileInputStream(privateKeyFile));
        } else {
            Password password = new Password(jpfPassword.getPassword());
            privateKey = MsPvkUtil.loadEncrypted(new FileInputStream(privateKeyFile), password);
        }
        return privateKey;
    } catch (PrivateKeyEncryptedException ex) {
        JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairPvk.PrivateKeyEncrypted.message"), privateKeyFile), getTitle(), JOptionPane.WARNING_MESSAGE);
        jcbEncrypted.setSelected(true);
        return null;
    } catch (PrivateKeyUnencryptedException ex) {
        JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairPvk.PrivateKeyNotEncrypted.message"), privateKeyFile), getTitle(), JOptionPane.WARNING_MESSAGE);
        jcbEncrypted.setSelected(false);
        return null;
    } catch (FileNotFoundException ex) {
        JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairPvk.NoReadFile.message"), privateKeyFile), getTitle(), JOptionPane.WARNING_MESSAGE);
        return null;
    } catch (Exception ex) {
        Problem problem = createLoadPvkProblem(ex, privateKeyFile);
        DProblem dProblem = new DProblem(this, res.getString("DImportKeyPairPvk.ProblemLoadingPvk.Title"), problem);
        dProblem.setLocationRelativeTo(this);
        dProblem.setVisible(true);
        return null;
    }
}
Also used : PrivateKeyEncryptedException(org.kse.crypto.privatekey.PrivateKeyEncryptedException) PrivateKeyUnencryptedException(org.kse.crypto.privatekey.PrivateKeyUnencryptedException) PrivateKey(java.security.PrivateKey) DViewPrivateKey(org.kse.gui.dialogs.DViewPrivateKey) FileNotFoundException(java.io.FileNotFoundException) Problem(org.kse.gui.error.Problem) DProblem(org.kse.gui.error.DProblem) File(java.io.File) FileInputStream(java.io.FileInputStream) CryptoException(org.kse.crypto.CryptoException) PrivateKeyUnencryptedException(org.kse.crypto.privatekey.PrivateKeyUnencryptedException) FileNotFoundException(java.io.FileNotFoundException) PrivateKeyEncryptedException(org.kse.crypto.privatekey.PrivateKeyEncryptedException) DProblem(org.kse.gui.error.DProblem) Password(org.kse.crypto.Password)

Aggregations

File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 FileNotFoundException (java.io.FileNotFoundException)3 PrivateKey (java.security.PrivateKey)3 CryptoException (org.kse.crypto.CryptoException)3 Password (org.kse.crypto.Password)3 PrivateKeyEncryptedException (org.kse.crypto.privatekey.PrivateKeyEncryptedException)3 PrivateKeyUnencryptedException (org.kse.crypto.privatekey.PrivateKeyUnencryptedException)3 DViewPrivateKey (org.kse.gui.dialogs.DViewPrivateKey)3 DProblem (org.kse.gui.error.DProblem)3 Problem (org.kse.gui.error.Problem)3 PrivateKeyPbeNotSupportedException (org.kse.crypto.privatekey.PrivateKeyPbeNotSupportedException)2