private void sendRSA() { try { // print local cipherTextArea.append("RSAE" + rsa.getE()); cipherTextArea.append("RSAN" + rsa.getN()); // send the RSA stuff outputStrm.writeObject("RSAE" + rsa.getE()); outputStrm.writeObject("RSAN" + rsa.getN()); outputStrm.flush(); } catch (IOException e) { chatTextWindow.append(" Something messed up!\n"); } }
private void buildGUI() { Border border = BorderFactory.createLineBorder(Color.black, 1, false); Border empty = new EmptyBorder(4, 4, 4, 4); CompoundBorder cborder = new CompoundBorder(border, empty); chatTextWindow.setBorder(cborder); jsp = new JScrollPane(chatTextWindow); chatPanel.add(jsp); sb = jsp.getVerticalScrollBar(); inputPanel = new JPanel(); inputPanel.setLayout(new GridLayout(0, 1, 0, 0)); border = BorderFactory.createLineBorder(Color.black, 1, false); // createLineBorder(Color.BLACK); empty = new EmptyBorder(4, 4, 4, 4); cborder = new CompoundBorder(border, empty); userText = new JTextArea(); userText.setToolTipText(""); userText.setWrapStyleWord(true); userText.setLineWrap(true); userText.setBorder(cborder); // userText.setMargin(new Insets(20, 20, 20, 20)); userText.setFont(new Font("Tahoma", Font.PLAIN, 13)); // add(); inputPanel.add(new JScrollPane(userText)); btnSend = new JButton("Send"); btnSend.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { userName = nameTextField.getText(); sendMessage(userText.getText()); userText.setText(""); } }); btnSend.setFont(new Font("Tahoma", Font.PLAIN, 13)); btnSend.setEnabled(false); JPanel panelCipher = new JPanel(); panelCipher.setLayout(new GridLayout(0, 1, 0, 0)); JLabel lblCiphertext = new JLabel("CipherText:"); JTabbedPane panelChoice = new JTabbedPane(JTabbedPane.TOP); JPanel panelStart = new JPanel(); panelStart.setBorder( new TitledBorder( new LineBorder(new Color(0, 0, 0)), "Connection", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0))); JLabel lblConversationAndPlain = new JLabel("Conversation and Plain Text:"); lblThankYou = new JLabel("Thank you for using our Secure Instant Messager"); lblThankYou.setHorizontalAlignment(SwingConstants.CENTER); lblNewLabel_1 = new JLabel("Designed and Developed by Adam Gorman and Unknown other"); lblNewLabel_1.setHorizontalAlignment(SwingConstants.CENTER); GroupLayout groupLayout = new GroupLayout(getContentPane()); groupLayout.setHorizontalGroup( groupLayout .createParallelGroup(Alignment.LEADING) .addGroup( groupLayout .createSequentialGroup() .addContainerGap() .addGroup( groupLayout .createParallelGroup(Alignment.LEADING) .addComponent( inputPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup( groupLayout .createSequentialGroup() .addGap(10) .addComponent(lblConversationAndPlain)) .addComponent(chatPanel, 0, 0, Short.MAX_VALUE) .addComponent( panelStart, GroupLayout.PREFERRED_SIZE, 440, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup( groupLayout .createParallelGroup(Alignment.LEADING) .addGroup( groupLayout .createSequentialGroup() .addComponent( btnSend, GroupLayout.PREFERRED_SIZE, 83, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED) .addGroup( groupLayout .createParallelGroup(Alignment.LEADING, false) .addComponent( lblNewLabel_1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent( lblThankYou, GroupLayout.DEFAULT_SIZE, 415, Short.MAX_VALUE)) .addGap(165)) .addGroup( groupLayout .createSequentialGroup() .addGap(10) .addComponent(lblCiphertext)) .addGroup( groupLayout .createParallelGroup(Alignment.TRAILING, false) .addComponent(panelChoice, Alignment.LEADING) .addComponent( panelCipher, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 530, Short.MAX_VALUE))) .addGap(41))); groupLayout.setVerticalGroup( groupLayout .createParallelGroup(Alignment.LEADING) .addGroup( groupLayout .createSequentialGroup() .addContainerGap() .addGroup( groupLayout .createParallelGroup(Alignment.LEADING) .addComponent( panelStart, GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE) .addComponent( panelChoice, GroupLayout.PREFERRED_SIZE, 101, Short.MAX_VALUE)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup( groupLayout .createParallelGroup(Alignment.BASELINE) .addComponent(lblCiphertext) .addComponent(lblConversationAndPlain)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup( groupLayout .createParallelGroup(Alignment.LEADING) .addComponent( panelCipher, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent( chatPanel, GroupLayout.PREFERRED_SIZE, 434, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup( groupLayout .createParallelGroup(Alignment.LEADING) .addComponent( inputPanel, GroupLayout.PREFERRED_SIZE, 48, GroupLayout.PREFERRED_SIZE) .addComponent( btnSend, GroupLayout.PREFERRED_SIZE, 48, GroupLayout.PREFERRED_SIZE) .addGroup( groupLayout .createSequentialGroup() .addComponent(lblThankYou) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(lblNewLabel_1))) .addContainerGap())); panelStart.setLayout(null); lblIp = new JLabel("IP:"); lblIp.setBounds(37, 59, 22, 16); panelStart.add(lblIp); lblIp.setHorizontalAlignment(SwingConstants.RIGHT); JLabel lblName = new JLabel("Name:"); lblName.setBounds(10, 25, 49, 16); panelStart.add(lblName); lblName.setHorizontalAlignment(SwingConstants.RIGHT); lblName.setFont(new Font("Tahoma", Font.PLAIN, 13)); nameTextField = new JTextField(); nameTextField.setBounds(66, 22, 138, 22); panelStart.add(nameTextField); nameTextField.setText("AliceBob"); nameTextField.setColumns(10); btnHost = new JButton("Host"); btnHost.setBounds(216, 21, 97, 25); panelStart.add(btnHost); btnJoin = new JButton("Join"); btnJoin.setBounds(216, 55, 97, 25); panelStart.add(btnJoin); ipHostTextField = new JTextField(); ipHostTextField.setBounds(66, 56, 138, 22); panelStart.add(ipHostTextField); ipHostTextField.setText("127.0.0.1"); ipHostTextField.setColumns(10); btnJoin.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { serverIP = ipHostTextField.getText(); btnJoin.setEnabled(false); btnHost.setEnabled(false); new Thread( new Runnable() { @Override public void run() { startRunning(); } }) .start(); } }); btnHost.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { btnJoin.setEnabled(false); btnHost.setEnabled(false); new Thread( new Runnable() { @Override public void run() { StartHosting(); } }) .start(); } }); JPanel panel_5 = new JPanel(); panelChoice.addTab(" Settings ", null, panel_5, null); buildRadio(panel_5); JPanel panel_6 = new JPanel(); panelChoice.addTab(" Caesar Shift ", null, panel_6, null); panel_6.setLayout(new GridLayout(0, 1, 5, 0)); lblShiftAmount = new JLabel("Shift Amount: "); lblShiftAmount.setHorizontalAlignment(SwingConstants.CENTER); panel_6.add(lblShiftAmount); textFieldShift = new JTextField(); textFieldShift.setHorizontalAlignment(SwingConstants.CENTER); textFieldShift.setText("0"); panel_6.add(textFieldShift); textFieldShift.setColumns(10); btnCShiftApply = new JButton("Apply"); btnCShiftApply.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) {} }); panel_6.add(btnCShiftApply); scrollPane = new JScrollPane(); sb2 = scrollPane.getVerticalScrollBar(); panelCipher.add(scrollPane); cipherTextArea = new JTextArea(); cipherTextArea.setBorder(cborder); scrollPane.setViewportView(cipherTextArea); cipherTextArea.setLineWrap(true); cipherTextArea.setWrapStyleWord(true); getContentPane().setLayout(groupLayout); userText.addKeyListener( new KeyAdapter() { @Override public void keyPressed(KeyEvent k) { if (k.getKeyChar() == KeyEvent.VK_ENTER) { userName = nameTextField.getText(); sendMessage(userText.getText()); } } @Override public void keyReleased(KeyEvent k) { if (k.getKeyChar() == KeyEvent.VK_ENTER) { userText.setText(""); } } }); setSize(1010, 700); menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu mnFile = new JMenu("File"); menuBar.add(mnFile); JMenuItem mntmExit = new JMenuItem("Exit"); mntmExit.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { safelyShutDown(); // setVisible(false); // dispose(); } }); mnFile.add(mntmExit); panel_2 = new JPanel(); panelChoice.addTab(" Vigenere Cipher ", null, panel_2, null); panel_2.setLayout(new GridLayout(0, 1, 0, 0)); JLabel lblSymmetricPassword = new JLabel("Symmetric password:"******"Apply"); btnVigApply.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) {} }); panel_2.add(btnVigApply); panel_3 = new JPanel(); panelChoice.addTab(" TEA ", null, panel_3, null); panel_3.setLayout(new GridLayout(0, 1, 0, 0)); JLabel lblSymmetricPassphrase = new JLabel("Symmetric passphrase:"); lblSymmetricPassphrase.setHorizontalAlignment(SwingConstants.CENTER); panel_3.add(lblSymmetricPassphrase); textFieldTEA = new JTextField(); textFieldTEA.setHorizontalAlignment(SwingConstants.CENTER); panel_3.add(textFieldTEA); textFieldTEA.setColumns(10); JButton btnApplyTEA = new JButton("Apply"); btnApplyTEA.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) {} }); panel_3.add(btnApplyTEA); panel_1 = new JPanel(); panelChoice.addTab(" RSA ", null, panel_1, null); panel_1.setLayout(null); lblNewLabel = new JLabel("Public (e):"); lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel.setBounds(12, 13, 77, 16); panel_1.add(lblNewLabel); RSAPublicE = new JTextField(); RSAPublicE.setText("65324"); RSAPublicE.setBounds(101, 10, 412, 22); panel_1.add(RSAPublicE); RSAPublicE.setColumns(10); lblModulus = new JLabel("Modulus (N):"); lblModulus.setHorizontalAlignment(SwingConstants.RIGHT); lblModulus.setBounds(12, 42, 77, 16); panel_1.add(lblModulus); RSAPublicN = new JTextField(); RSAPublicN.setHorizontalAlignment(SwingConstants.LEFT); // RSAPublicN.setText("8256"); RSAPublicN.setBounds(101, 39, 412, 22); panel_1.add(RSAPublicN); RSAPublicN.setColumns(10); RSAPublicE.setText(rsa.getE().toString()); RSAPublicN.setText(rsa.getN().toString()); }