use of org.kse.crypto.privatekey.OpenSslPbeType in project keystore-explorer by kaikramer.
the class DExportPrivateKeyOpenSsl 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("DExportPrivateKeyOpenSsl.jlEncrypt.text"));
GridBagConstraints gbc_jlEncrypt = (GridBagConstraints) gbcLbl.clone();
gbc_jlEncrypt.gridy = 0;
jcbEncrypt = new JCheckBox();
jcbEncrypt.setSelected(true);
jcbEncrypt.setToolTipText(res.getString("DExportPrivateKeyOpenSsl.jcbEncrypt.tooltip"));
GridBagConstraints gbc_jcbEncrypt = (GridBagConstraints) gbcEdCtrl.clone();
gbc_jcbEncrypt.gridy = 0;
jcbEncrypt.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent evt) {
if (jcbEncrypt.isSelected()) {
jcbExportPem.setSelected(true);
jcbExportPem.setEnabled(false);
} else {
jcbExportPem.setEnabled(true);
}
}
});
jlPbeAlg = new JLabel(res.getString("DExportPrivateKeyOpenSsl.jlPbeAlg.text"));
GridBagConstraints gbc_jlPbeAlg = (GridBagConstraints) gbcLbl.clone();
gbc_jlPbeAlg.gridy = 1;
jcbPbeAlg = new JComboBox<OpenSslPbeType>();
populatePbeAlgs();
jcbPbeAlg.setToolTipText(res.getString("DExportPrivateKeyOpenSsl.jcbPbeAlg.tooltip"));
jcbPbeAlg.setSelectedIndex(0);
GridBagConstraints gbc_jcbPbeAlg = (GridBagConstraints) gbcEdCtrl.clone();
gbc_jcbPbeAlg.gridy = 1;
jlPassword = new JLabel(res.getString("DExportPrivateKeyOpenSsl.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("DExportPrivateKeyOpenSsl.jpqfPassword.tooltip"));
GridBagConstraints gbc_jpfPassword = (GridBagConstraints) gbcEdCtrl.clone();
gbc_jpfPassword.gridy = 2;
jlConfirmPassword = new JLabel(res.getString("DExportPrivateKeyOpenSsl.jlConfirmPassword.text"));
GridBagConstraints gbc_jlConfirmPassword = (GridBagConstraints) gbcLbl.clone();
gbc_jlConfirmPassword.gridy = 3;
jpfConfirmPassword = new JPasswordField(15);
jpfConfirmPassword.setToolTipText(res.getString("DExportPrivateKeyOpenSsl.jpfConfirmPassword.tooltip"));
GridBagConstraints gbc_jpfConfirmPassword = (GridBagConstraints) gbcEdCtrl.clone();
gbc_jpfConfirmPassword.gridy = 3;
jlExportPem = new JLabel(res.getString("DExportPrivateKeyOpenSsl.jlExportPem.text"));
GridBagConstraints gbc_jlExportPem = (GridBagConstraints) gbcLbl.clone();
gbc_jlExportPem.gridy = 4;
jcbExportPem = new JCheckBox();
jcbExportPem.setSelected(true);
// Itinitla export setting is with
jcbExportPem.setEnabled(false);
// encryption - must be pem
// export
jcbExportPem.setToolTipText(res.getString("DExportPrivateKeyOpenSsl.jcbExportPem.tooltip"));
GridBagConstraints gbc_jcbExportPem = (GridBagConstraints) gbcEdCtrl.clone();
gbc_jcbExportPem.gridy = 4;
jlExportFile = new JLabel(res.getString("DExportPrivateKeyOpenSsl.jlExportFile.text"));
GridBagConstraints gbc_jlExportFile = (GridBagConstraints) gbcLbl.clone();
gbc_jlExportFile.gridy = 5;
jtfExportFile = new JTextField(30);
jtfExportFile.setToolTipText(res.getString("DExportPrivateKeyOpenSsl.jtfExportFile.tooltip"));
GridBagConstraints gbc_jtfExportFile = (GridBagConstraints) gbcEdCtrl.clone();
gbc_jtfExportFile.gridy = 5;
gbc_jtfExportFile.gridwidth = 6;
jbBrowse = new JButton(res.getString("DExportPrivateKeyOpenSsl.jbBrowse.text"));
jbBrowse.setToolTipText(res.getString("DExportPrivateKeyOpenSsl.jbBrowse.tooltip"));
PlatformUtil.setMnemonic(jbBrowse, res.getString("DExportPrivateKeyOpenSsl.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(DExportPrivateKeyOpenSsl.this);
browsePressed();
} finally {
CursorUtil.setCursorFree(DExportPrivateKeyOpenSsl.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("DExportPrivateKeyOpenSsl.jbExport.text"));
PlatformUtil.setMnemonic(jbExport, res.getString("DExportPrivateKeyOpenSsl.jbExport.mnemonic").charAt(0));
jbExport.setToolTipText(res.getString("DExportPrivateKeyOpenSsl.jbExport.tooltip"));
jbExport.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
try {
CursorUtil.setCursorBusy(DExportPrivateKeyOpenSsl.this);
exportPressed();
} finally {
CursorUtil.setCursorFree(DExportPrivateKeyOpenSsl.this);
}
}
});
jbCancel = new JButton(res.getString("DExportPrivateKeyOpenSsl.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("DExportPrivateKeyOpenSsl.Title"), entryAlias));
setResizable(false);
getRootPane().setDefaultButton(jbExport);
populateExportFileName();
pack();
}
use of org.kse.crypto.privatekey.OpenSslPbeType in project keystore-explorer by kaikramer.
the class ExportKeyPairPrivateKeyAction method exportAsOpenSsl.
private void exportAsOpenSsl(PrivateKey privateKey, String alias) throws CryptoException, IOException {
File exportFile = null;
try {
DExportPrivateKeyOpenSsl dExportPrivateKeyOpenSsl = new DExportPrivateKeyOpenSsl(frame, alias, applicationSettings.getPasswordQualityConfig());
dExportPrivateKeyOpenSsl.setLocationRelativeTo(frame);
dExportPrivateKeyOpenSsl.setVisible(true);
if (!dExportPrivateKeyOpenSsl.exportSelected()) {
return;
}
exportFile = dExportPrivateKeyOpenSsl.getExportFile();
boolean pemEncode = dExportPrivateKeyOpenSsl.pemEncode();
boolean encrypt = dExportPrivateKeyOpenSsl.encrypt();
OpenSslPbeType pbeAlgorithm = null;
Password exportPassword = null;
if (encrypt) {
pbeAlgorithm = dExportPrivateKeyOpenSsl.getPbeAlgorithm();
exportPassword = dExportPrivateKeyOpenSsl.getExportPassword();
}
byte[] encoded = getOpenSslEncodedPrivateKey(privateKey, pemEncode, pbeAlgorithm, exportPassword);
exportEncodedPrivateKey(encoded, exportFile);
JOptionPane.showMessageDialog(frame, res.getString("ExportKeyPairPrivateKeyAction.ExportPrivateKeyOpenSslSuccessful.message"), res.getString("ExportKeyPairPrivateKeyAction.ExportPrivateKeyOpenSsl.Title"), JOptionPane.INFORMATION_MESSAGE);
} catch (FileNotFoundException ex) {
String message = MessageFormat.format(res.getString("ExportKeyPairPrivateKeyAction.NoWriteFile.message"), exportFile);
JOptionPane.showMessageDialog(frame, message, res.getString("ExportKeyPairPrivateKeyAction.ExportPrivateKeyOpenSsl.Title"), JOptionPane.WARNING_MESSAGE);
}
}
Aggregations