Search in sources :

Example 1 with Pkcs8PbeType

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

the class DExportPrivateKeyPkcs8 method initComponents.

private void initComponents() {
    GridBagConstraints gbcLbl = new GridBagConstraints();
    gbcLbl.gridx = 0;
    gbcLbl.gridwidth = 3;
    gbcLbl.gridheight = 1;
    gbcLbl.insets = new Insets(5, 5, 5, 5);
    gbcLbl.anchor = GridBagConstraints.EAST;
    GridBagConstraints gbcEdCtrl = new GridBagConstraints();
    gbcEdCtrl.gridx = 3;
    gbcEdCtrl.gridwidth = 3;
    gbcEdCtrl.gridheight = 1;
    gbcEdCtrl.insets = new Insets(5, 5, 5, 5);
    gbcEdCtrl.anchor = GridBagConstraints.WEST;
    jlEncrypt = new JLabel(res.getString("DExportPrivateKeyPkcs8.jlEncrypt.text"));
    GridBagConstraints gbc_jlEncrypt = (GridBagConstraints) gbcLbl.clone();
    gbc_jlEncrypt.gridy = 0;
    jcbEncrypt = new JCheckBox();
    jcbEncrypt.setSelected(true);
    jcbEncrypt.setToolTipText(res.getString("DExportPrivateKeyPkcs8.jcbEncrypt.tooltip"));
    GridBagConstraints gbc_jcbEncrypt = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jcbEncrypt.gridy = 0;
    jlPbeAlg = new JLabel(res.getString("DExportPrivateKeyPkcs8.jlPbeAlg.text"));
    GridBagConstraints gbc_jlPbeAlg = (GridBagConstraints) gbcLbl.clone();
    gbc_jlPbeAlg.gridy = 1;
    jcbPbeAlg = new JComboBox<Pkcs8PbeType>();
    populatePbeAlgs();
    jcbPbeAlg.setToolTipText(res.getString("DExportPrivateKeyPkcs8.jcbPbeAlg.tooltip"));
    jcbPbeAlg.setSelectedIndex(0);
    GridBagConstraints gbc_jcbPbeAlg = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jcbPbeAlg.gridy = 1;
    jlPassword = new JLabel(res.getString("DExportPrivateKeyPkcs8.jlPassword.text"));
    GridBagConstraints gbc_jlPassword = (GridBagConstraints) gbcLbl.clone();
    gbc_jlPassword.gridy = 2;
    if (passwordQualityConfig.getEnabled()) {
        if (passwordQualityConfig.getEnforced()) {
            jpfPassword = new JPasswordQualityField(15, passwordQualityConfig.getMinimumQuality());
        } else {
            jpfPassword = new JPasswordQualityField(15);
        }
    } else {
        jpfPassword = new JPasswordField(15);
    }
    jpfPassword.setToolTipText(res.getString("DExportPrivateKeyPkcs8.jpqfPassword.tooltip"));
    GridBagConstraints gbc_jpfPassword = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jpfPassword.gridy = 2;
    jlConfirmPassword = new JLabel(res.getString("DExportPrivateKeyPkcs8.jlConfirmPassword.text"));
    GridBagConstraints gbc_jlConfirmPassword = (GridBagConstraints) gbcLbl.clone();
    gbc_jlConfirmPassword.gridy = 3;
    jpfConfirmPassword = new JPasswordField(15);
    jpfConfirmPassword.setToolTipText(res.getString("DExportPrivateKeyPkcs8.jpfConfirmPassword.tooltip"));
    GridBagConstraints gbc_jpfConfirmPassword = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jpfConfirmPassword.gridy = 3;
    jlExportPem = new JLabel(res.getString("DExportPrivateKeyPkcs8.jlExportPem.text"));
    GridBagConstraints gbc_jlExportPem = (GridBagConstraints) gbcLbl.clone();
    gbc_jlExportPem.gridy = 4;
    jcbExportPem = new JCheckBox();
    jcbExportPem.setSelected(true);
    jcbExportPem.setToolTipText(res.getString("DExportPrivateKeyPkcs8.jcbExportPem.tooltip"));
    GridBagConstraints gbc_jcbExportPem = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jcbExportPem.gridy = 4;
    jlExportFile = new JLabel(res.getString("DExportPrivateKeyPkcs8.jlExportFile.text"));
    GridBagConstraints gbc_jlExportFile = (GridBagConstraints) gbcLbl.clone();
    gbc_jlExportFile.gridy = 5;
    jtfExportFile = new JTextField(30);
    jtfExportFile.setToolTipText(res.getString("DExportPrivateKeyPkcs8.jtfExportFile.tooltip"));
    GridBagConstraints gbc_jtfExportFile = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jtfExportFile.gridy = 5;
    gbc_jtfExportFile.gridwidth = 6;
    jbBrowse = new JButton(res.getString("DExportPrivateKeyPkcs8.jbBrowse.text"));
    jbBrowse.setToolTipText(res.getString("DExportPrivateKeyPkcs8.jbBrowse.tooltip"));
    PlatformUtil.setMnemonic(jbBrowse, res.getString("DExportPrivateKeyPkcs8.jbBrowse.mnemonic").charAt(0));
    GridBagConstraints gbc_jbBrowse = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jbBrowse.gridy = 5;
    gbc_jbBrowse.gridx = 9;
    jbBrowse.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DExportPrivateKeyPkcs8.this);
                browsePressed();
            } finally {
                CursorUtil.setCursorFree(DExportPrivateKeyPkcs8.this);
            }
        }
    });
    jpOptions = new JPanel(new GridBagLayout());
    jpOptions.setBorder(new CompoundBorder(new CompoundBorder(new EmptyBorder(5, 5, 5, 5), new EtchedBorder()), new EmptyBorder(5, 5, 5, 5)));
    jpOptions.add(jlEncrypt, gbc_jlEncrypt);
    jpOptions.add(jcbEncrypt, gbc_jcbEncrypt);
    jpOptions.add(jlPbeAlg, gbc_jlPbeAlg);
    jpOptions.add(jcbPbeAlg, gbc_jcbPbeAlg);
    jpOptions.add(jlPassword, gbc_jlPassword);
    jpOptions.add(jpfPassword, gbc_jpfPassword);
    jpOptions.add(jlConfirmPassword, gbc_jlConfirmPassword);
    jpOptions.add(jpfConfirmPassword, gbc_jpfConfirmPassword);
    jpOptions.add(jlExportPem, gbc_jlExportPem);
    jpOptions.add(jcbExportPem, gbc_jcbExportPem);
    jpOptions.add(jlExportFile, gbc_jlExportFile);
    jpOptions.add(jtfExportFile, gbc_jtfExportFile);
    jpOptions.add(jbBrowse, gbc_jbBrowse);
    jcbEncrypt.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent evt) {
            if (jcbEncrypt.isSelected()) {
                jcbPbeAlg.setEnabled(true);
                jpfPassword.setEnabled(true);
                jpfConfirmPassword.setEnabled(true);
            } else {
                jcbPbeAlg.setEnabled(false);
                jpfPassword.setEnabled(false);
                if (jpfPassword instanceof JPasswordQualityField) {
                    ((JPasswordQualityField) jpfPassword).setText("");
                } else {
                    ((JPasswordField) jpfPassword).setText("");
                }
                jpfConfirmPassword.setEnabled(false);
                jpfConfirmPassword.setText("");
            }
        }
    });
    jbExport = new JButton(res.getString("DExportPrivateKeyPkcs8.jbExport.text"));
    PlatformUtil.setMnemonic(jbExport, res.getString("DExportPrivateKeyPkcs8.jbExport.mnemonic").charAt(0));
    jbExport.setToolTipText(res.getString("DExportPrivateKeyPkcs8.jbExport.tooltip"));
    jbExport.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DExportPrivateKeyPkcs8.this);
                exportPressed();
            } finally {
                CursorUtil.setCursorFree(DExportPrivateKeyPkcs8.this);
            }
        }
    });
    jbCancel = new JButton(res.getString("DExportPrivateKeyPkcs8.jbCancel.text"));
    jbCancel.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            cancelPressed();
        }
    });
    jbCancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), CANCEL_KEY);
    jbCancel.getActionMap().put(CANCEL_KEY, new AbstractAction() {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent evt) {
            cancelPressed();
        }
    });
    jpButtons = PlatformUtil.createDialogButtonPanel(jbExport, jbCancel, false);
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(jpOptions, BorderLayout.CENTER);
    getContentPane().add(jpButtons, BorderLayout.SOUTH);
    addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent evt) {
            closeDialog();
        }
    });
    setTitle(MessageFormat.format(res.getString("DExportPrivateKeyPkcs8.Title"), entryAlias));
    setResizable(false);
    getRootPane().setDefaultButton(jbExport);
    populateExportFileName();
    pack();
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) ItemEvent(java.awt.event.ItemEvent) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) WindowAdapter(java.awt.event.WindowAdapter) JTextField(javax.swing.JTextField) BorderLayout(java.awt.BorderLayout) JPasswordQualityField(org.kse.gui.password.JPasswordQualityField) CompoundBorder(javax.swing.border.CompoundBorder) EmptyBorder(javax.swing.border.EmptyBorder) AbstractAction(javax.swing.AbstractAction) Pkcs8PbeType(org.kse.crypto.privatekey.Pkcs8PbeType) JLabel(javax.swing.JLabel) JCheckBox(javax.swing.JCheckBox) EtchedBorder(javax.swing.border.EtchedBorder) ActionListener(java.awt.event.ActionListener) JPasswordField(javax.swing.JPasswordField) WindowEvent(java.awt.event.WindowEvent) ItemListener(java.awt.event.ItemListener)

Example 2 with Pkcs8PbeType

use of org.kse.crypto.privatekey.Pkcs8PbeType 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

Pkcs8PbeType (org.kse.crypto.privatekey.Pkcs8PbeType)2 BorderLayout (java.awt.BorderLayout)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 AbstractAction (javax.swing.AbstractAction)1 JButton (javax.swing.JButton)1 JCheckBox (javax.swing.JCheckBox)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 JPasswordField (javax.swing.JPasswordField)1 JTextField (javax.swing.JTextField)1