Search in sources :

Example 56 with Password

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

the class DGetPassword method okPressed.

private void okPressed() {
    password = new Password(jpfPassword.getPassword());
    closeDialog();
}
Also used : Password(org.kse.crypto.Password)

Example 57 with Password

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

the class DProperties method createPrivateKeyNodes.

private void createPrivateKeyNodes(DefaultMutableTreeNode parentNode, String alias) throws CryptoException {
    try {
        KeyStore keyStore = currentState.getKeyStore();
        Password password = getEntryPassword(alias);
        if (password == null) {
            DefaultMutableTreeNode privateKeyNode = new DefaultMutableTreeNode(res.getString("DProperties.properties.PrivateKey"));
            parentNode.add(privateKeyNode);
            DefaultMutableTreeNode lockedNode = new DefaultMutableTreeNode(res.getString("DProperties.properties.Locked"));
            privateKeyNode.add(lockedNode);
            return;
        }
        PrivateKey privateKey = (PrivateKey) keyStore.getKey(alias, password.toCharArray());
        createPrivateKeyNodes(parentNode, privateKey);
    } catch (NoSuchAlgorithmException ex) {
        throw new CryptoException(res.getString("DProperties.NoGetProperties.exception.message"), ex);
    } catch (KeyStoreException ex) {
        throw new CryptoException(res.getString("DProperties.NoGetProperties.exception.message"), ex);
    } catch (UnrecoverableKeyException ex) {
        throw new CryptoException(res.getString("DProperties.NoGetProperties.exception.message"), ex);
    }
}
Also used : PrivateKey(java.security.PrivateKey) DSAPrivateKey(java.security.interfaces.DSAPrivateKey) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) UnrecoverableKeyException(java.security.UnrecoverableKeyException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStoreException(java.security.KeyStoreException) CryptoException(org.kse.crypto.CryptoException) KeyStore(java.security.KeyStore) Password(org.kse.crypto.Password)

Example 58 with Password

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

the class DProperties method createKeyNodes.

private void createKeyNodes(DefaultMutableTreeNode parentNode, String alias) throws CryptoException {
    try {
        KeyStore keyStore = currentState.getKeyStore();
        DefaultMutableTreeNode keyNode = new DefaultMutableTreeNode(alias);
        parentNode.add(keyNode);
        createLastModifiedNode(keyNode, alias);
        Password password = getEntryPassword(alias);
        if (password == null) {
            DefaultMutableTreeNode lockedNode = new DefaultMutableTreeNode(res.getString("DProperties.properties.Locked"));
            keyNode.add(lockedNode);
            return;
        }
        Key key = keyStore.getKey(alias, password.toCharArray());
        if (key instanceof PublicKey) {
            createPublicKeyNodes(keyNode, (PublicKey) key);
        } else if (key instanceof PrivateKey) {
            createPrivateKeyNodes(keyNode, (PrivateKey) key);
        } else if (key instanceof SecretKey) {
            createSecretKeyNodes(keyNode, (SecretKey) key);
        }
    } catch (NoSuchAlgorithmException ex) {
        throw new CryptoException(res.getString("DProperties.NoGetProperties.exception.message"), ex);
    } catch (KeyStoreException ex) {
        throw new CryptoException(res.getString("DProperties.NoGetProperties.exception.message"), ex);
    } catch (UnrecoverableKeyException ex) {
        throw new CryptoException(res.getString("DProperties.NoGetProperties.exception.message"), ex);
    }
}
Also used : SecretKey(javax.crypto.SecretKey) PrivateKey(java.security.PrivateKey) DSAPrivateKey(java.security.interfaces.DSAPrivateKey) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) UnrecoverableKeyException(java.security.UnrecoverableKeyException) RSAPublicKey(java.security.interfaces.RSAPublicKey) PublicKey(java.security.PublicKey) DSAPublicKey(java.security.interfaces.DSAPublicKey) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStoreException(java.security.KeyStoreException) CryptoException(org.kse.crypto.CryptoException) KeyStore(java.security.KeyStore) RSAPublicKey(java.security.interfaces.RSAPublicKey) Key(java.security.Key) PrivateKey(java.security.PrivateKey) RSAPrivateCrtKey(java.security.interfaces.RSAPrivateCrtKey) SecretKey(javax.crypto.SecretKey) DSAPrivateKey(java.security.interfaces.DSAPrivateKey) PublicKey(java.security.PublicKey) DSAPublicKey(java.security.interfaces.DSAPublicKey) Password(org.kse.crypto.Password)

Example 59 with Password

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

the class PasswordCallbackHandler method handlePasswordCallback.

private void handlePasswordCallback(PasswordCallback passCb) throws UnsupportedCallbackException {
    DGetPassword dGetPassword = new DGetPassword(frame, res.getString("PasswordCallbackHandler.Title"));
    dGetPassword.setLocationRelativeTo(frame);
    dGetPassword.setVisible(true);
    Password password = dGetPassword.getPassword();
    if (password == null) {
        throw new CancellationException("Password Callback canceled by user");
    }
    passCb.setPassword(password.toCharArray());
}
Also used : DGetPassword(org.kse.gui.password.DGetPassword) CancellationException(java.util.concurrent.CancellationException) DGetPassword(org.kse.gui.password.DGetPassword) Password(org.kse.crypto.Password)

Example 60 with Password

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

the class DExportPrivateKeyPvk method exportPressed.

private void exportPressed() {
    if (jrbExchange.isSelected()) {
        keyType = MsPvkUtil.PVK_KEY_EXCHANGE;
    } else {
        keyType = MsPvkUtil.PVK_KEY_SIGNATURE;
    }
    encrypt = jcbEncrypt.isSelected();
    if (encrypt) {
        strongEncryption = jrbStrong.isSelected();
        Password firstPassword;
        if (jpfPassword instanceof JPasswordQualityField) {
            char[] firstPasswordChars = ((JPasswordQualityField) jpfPassword).getPassword();
            if (firstPasswordChars == null) {
                JOptionPane.showMessageDialog(this, res.getString("DExportPrivateKeyPvk.MinimumPasswordQualityNotMet.message"), res.getString("DExportPrivateKeyPvk.Simple.Title"), JOptionPane.WARNING_MESSAGE);
                return;
            }
            firstPassword = new Password(firstPasswordChars);
        } else {
            firstPassword = new Password(((JPasswordField) jpfPassword).getPassword());
        }
        Password confirmPassword = new Password(jpfConfirmPassword.getPassword());
        if (firstPassword.equals(confirmPassword)) {
            exportPassword = firstPassword;
        } else {
            JOptionPane.showMessageDialog(this, res.getString("DExportPrivateKeyPvk.PasswordsNoMatch.message"), res.getString("DExportPrivateKeyPvk.Simple.Title"), JOptionPane.WARNING_MESSAGE);
            return;
        }
    }
    String exportFileChars = jtfExportFile.getText().trim();
    if (exportFileChars.length() == 0) {
        JOptionPane.showMessageDialog(this, res.getString("DExportPrivateKeyPvk.ExportFileRequired.message"), res.getString("DExportPrivateKeyPvk.Simple.Title"), JOptionPane.WARNING_MESSAGE);
        return;
    }
    File exportFile = new File(exportFileChars);
    if (exportFile.isFile()) {
        String message = MessageFormat.format(res.getString("DExportPrivateKeyPvk.OverWriteExportFile.message"), exportFile);
        int selected = JOptionPane.showConfirmDialog(this, message, res.getString("DExportPrivateKeyPvk.Simple.Title"), JOptionPane.YES_NO_OPTION);
        if (selected != JOptionPane.YES_OPTION) {
            return;
        }
    }
    this.exportFile = exportFile;
    exportSelected = true;
    closeDialog();
}
Also used : JPasswordQualityField(org.kse.gui.password.JPasswordQualityField) JPasswordField(javax.swing.JPasswordField) File(java.io.File) Password(org.kse.crypto.Password)

Aggregations

Password (org.kse.crypto.Password)60 KeyStore (java.security.KeyStore)35 KeyStoreState (org.kse.utilities.history.KeyStoreState)32 KeyStoreHistory (org.kse.utilities.history.KeyStoreHistory)31 PrivateKey (java.security.PrivateKey)24 File (java.io.File)23 FileNotFoundException (java.io.FileNotFoundException)16 Key (java.security.Key)15 X509Certificate (java.security.cert.X509Certificate)15 Certificate (java.security.cert.Certificate)13 KeyStoreType (org.kse.crypto.keystore.KeyStoreType)12 CryptoException (org.kse.crypto.CryptoException)9 DProblem (org.kse.gui.error.DProblem)9 Problem (org.kse.gui.error.Problem)9 DGetAlias (org.kse.gui.dialogs.DGetAlias)8 DGetNewPassword (org.kse.gui.password.DGetNewPassword)8 JPasswordField (javax.swing.JPasswordField)6 DViewPrivateKey (org.kse.gui.dialogs.DViewPrivateKey)6 DGetPassword (org.kse.gui.password.DGetPassword)6 FileInputStream (java.io.FileInputStream)5