private static void updateRegisteredKeypairsTable() { DefaultTableModel defaultTableModel = (DefaultTableModel) keypairsTable.getModel(); while (defaultTableModel.getRowCount() != 0) { defaultTableModel.removeRow(0); } keypairs.clear(); ArrayList<KeypairPOJO> registeredKeypairs = null; try { registeredKeypairs = KeypairDAO.getKeypairs(); } catch (Exception e) { e.printStackTrace(); } if (registeredKeypairs != null) { for (KeypairPOJO keypair : registeredKeypairs) { defaultTableModel.addRow( new String[] { keypair.getKeypairDescription(), keypair.getGenerationTimestampAsString() }); keypairs.add(keypair); } } keypairsTable.setModel(defaultTableModel); }
/** Create the ViewKeys frame. */ public ViewKeys(JFrame homeFrame, String keypairDescription) { final JDialog viewGeneratedKeysFrame = new JDialog(homeFrame, "Generated RSA Key Pair", true); KeypairPOJO keypair = null; final KeypairPOJO finalKeypair; JPanel parentPanel = new JPanel(new BorderLayout()); JPanel textAreaPanel = new JPanel(new BorderLayout()); JPanel buttonsPanel = new JPanel(); buttonsPanel.setLayout(new GridLayout(1, 3, 10, 0)); JTextArea keyPairtextArea = new JTextArea(20, 70); keyPairtextArea.setEditable(false); // keyPairtextArea.setEnabled(false); keyPairtextArea.setLineWrap(true); ArrayList<KeypairPOJO> registeredKeypairs = null; try { registeredKeypairs = KeypairDAO.getKeypairs(); } catch (Exception e) { e.printStackTrace(); } if (keypairDescription == null) { if (registeredKeypairs.isEmpty()) { JOptionPane.showMessageDialog( null, "There are no keypairs registered.", "Notice", JOptionPane.INFORMATION_MESSAGE); } else { keypair = registeredKeypairs.get(registeredKeypairs.size() - 1); keyPairtextArea.setText( "-----BEGIN RSA PUBLIC KEY-----\n" + "Public Exponent: " + keypair.getPublicExponent() + "\n" + "Modulus: " + keypair.getModulus() + "\n" + "-----END RSA PUBLIC KEY-----\n" + "-----BEGIN RSA PRIVATE KEY-----\n" + "Private Exponent: " + keypair.getPrivateExponent() + "\n" + "Modulus: " + keypair.getModulus() + "\n" + "-----END RSA PRIVATE KEY-----"); } } else { try { keypair = KeypairDAO.getKeypairByDescription(keypairDescription); keyPairtextArea.setText( "-----BEGIN RSA PUBLIC KEY-----\n" + "Public Exponent: " + keypair.getPublicExponent() + "\n" + "Modulus: " + keypair.getModulus() + "\n" + "-----END RSA PUBLIC KEY-----\n" + "-----BEGIN RSA PRIVATE KEY-----\n" + "Private Exponent: " + keypair.getPrivateExponent() + "\n" + "Modulus: " + keypair.getModulus() + "\n" + "-----END RSA PRIVATE KEY-----"); } catch (Exception e) { e.printStackTrace(); } } finalKeypair = keypair; keyPairtextArea.addMouseListener(new PopUpMenuClickListener(keyPairtextArea)); textAreaPanel.add(keyPairtextArea); JButton exportKeyPairToFileButton = new JButton("Export to file"); exportKeyPairToFileButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { ExportKey.exportToFileAsPlainText(finalKeypair, viewGeneratedKeysFrame); } }); JButton purgeKeyPairButton = new JButton("Purge key pair"); purgeKeyPairButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { try { KeypairDAO.deleteKeypair(finalKeypair); viewGeneratedKeysFrame.dispose(); } catch (Exception e) { e.printStackTrace(); } } }); JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { viewGeneratedKeysFrame.dispose(); } }); buttonsPanel.add(exportKeyPairToFileButton); buttonsPanel.add(purgeKeyPairButton); buttonsPanel.add(cancelButton); // parentPanel.add(headerPanel, BorderLayout.NORTH); parentPanel.add(textAreaPanel, BorderLayout.CENTER); parentPanel.add(buttonsPanel, BorderLayout.SOUTH); viewGeneratedKeysFrame.setContentPane(parentPanel); viewGeneratedKeysFrame.pack(); viewGeneratedKeysFrame.validate(); viewGeneratedKeysFrame.setResizable(true); viewGeneratedKeysFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); viewGeneratedKeysFrame.setLocationRelativeTo(null); viewGeneratedKeysFrame.setVisible(true); }