package RSA.RSA_En; import java.awt.Color; import java.awt.EventQueue; import java.awt.Font; import java.awt.Toolkit; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.UnsupportedEncodingException; import java.net.ServerSocket; import java.net.Socket; import java.net.UnknownHostException; import java.security.InvalidKeyException; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; import java.security.PublicKey; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextArea; import javax.swing.JTextField; import RSA.Server; public class client extends JFrame{ static JFrame frame; private JTextField Sending; private static JTextField Writing_Area; static JTextArea Message_Area; static JButton Send; static Socket s; static Socket SocketSifre; static ServerSocket Sssifre; static ServerSocket ss; static DataInputStream dis; static DataOutputStream dos; static PublicKey GenelAnahtar ; static PrivateKey GizliAnahtar ; static Cipher şifrelimetin; static byte[] cipherText ; static ObjectInputStream disif; static ObjectOutputStream dosif; /*public static String Encrypt(String Mesaj) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException { KeyPairGenerator birçiftanahtar = KeyPairGenerator.getInstance("RSA"); birçiftanahtar.initialize(2048); KeyPair anahtar = birçiftanahtar.generateKeyPair(); GenelAnahtar = anahtar.getPublic(); GizliAnahtar = anahtar.getPrivate(); şifrelimetin = Cipher.getInstance("RSA/ECB/PKCS1Padding"); şifrelimetin.init(Cipher.ENCRYPT_MODE,GenelAnahtar); byte[] input = Mesaj.getBytes() ; cipherText = şifrelimetin.doFinal(); Message_Area.setText(new String(cipherText ,"UTF-8") + Mesaj); String MyMessage = new String(cipherText ,"UTF-8") + Mesaj; return MyMessage; } */ public static void main(String[] args) { frame = new JFrame(); frame.setResizable(false); frame.setTitle("Necmettin Erbakan \u00DCniversitesi"); frame.setIconImage(Toolkit.getDefaultToolkit().getImage("C:\\Users\\BORNOVALI\\Desktop\\necmettin-erbakan-universitesi-logo-63C897B098-seeklogo.com.png")); frame.getContentPane().setBackground(new Color(0, 204, 204)); frame.setBounds(150, 150, 1150, 450); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(null); Message_Area = new JTextArea(); Message_Area.setForeground(new Color(0, 0, 51)); Message_Area.setEnabled(false); Message_Area.setEditable(false); Message_Area.setBackground(new Color(153, 204, 51)); Message_Area.setFont(new Font("HelveticaNeue Condensed", Font.PLAIN, 14)); Message_Area.setBounds(10, 10, 753, 140); frame.getContentPane().add(Message_Area); Message_Area.setColumns(10); Message_Area.setLineWrap(true); Send = new JButton("G\u00F6nder"); Send.setFont(new Font("HelveticaNeue Condensed", Font.PLAIN, 14)); Send.setBounds(690, 198, 89, 150); frame.getContentPane().add(Send); JLabel lblNewLabel = new JLabel("New label"); lblNewLabel.setIcon(new ImageIcon("C:\\Users\\BORNOVALI\\Desktop\\Necmettin_Erbakan_\u00DCniversitesi_logosu.png")); lblNewLabel.setBounds(800, 11, 321, 300); frame.getContentPane().add(lblNewLabel); Writing_Area = new JTextField(); Writing_Area.setForeground(new Color(0, 0, 51)); Writing_Area.setFont(new Font("HelveticaNeue Condensed", Font.PLAIN, 11)); Writing_Area.setBounds(10, 187, 648, 150); frame.getContentPane().add(Writing_Area); Writing_Area.setColumns(10); Send.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { String Girilen_Metin = Writing_Area.getText(); try { dos.writeUTF(Girilen_Metin); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); EventQueue.invokeLater(new Runnable() { public void run() { try { client window = new client(); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); String metin = ""; try { s = new Socket("localhost", 1234); dis = new DataInputStream(s.getInputStream()); dos = new DataOutputStream(s.getOutputStream()); while(!metin.equals("Exit")) { metin = dis.readUTF(); Message_Area.setText("Client Diyor ki ; " + Writing_Area.getText().toString() + "\n" + metin); } } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /* SocketSifre = new Socket("localhost",4321); disif = new ObjectInputStream(SocketSifre.getInputStream()); dosif = new ObjectOutputStream(SocketSifre.getOutputStream()); */ }