Untitled
4 years ago in Plain Text
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.security.InvalidKeyException;
import java.security.PrivateKey;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import RSA.Server;
public class server extends JFrame{
static JFrame frame;
private JTextField Sending;
private static JTextField Writing_Area;
static JTextArea Message_Area;
static JButton Send;
static Socket s;
static ServerSocket ss;
static Socket SocketSifre;
static ServerSocket Sssifre;
static DataInputStream dis;
static DataOutputStream dos;
static ObjectInputStream disif;
static ObjectOutputStream dosif;
public static void Decyrpt(Cipher şifrelimetin , PrivateKey ÖzelAnahtar , byte[] Gelenmetin)
throws IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException {
try {
şifrelimetin.init(Cipher.DECRYPT_MODE, ÖzelAnahtar);
byte[] decipheredText = şifrelimetin.doFinal(Gelenmetin);
Message_Area.setText(new String(decipheredText, "UTF8").toString());
} catch (InvalidKeyException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) throws ClassNotFoundException {
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) {
try {
String Girilen_Metin = Writing_Area.getText();
dos.writeUTF(Girilen_Metin.toString());
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
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);
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
server window = new server();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
String metin = "";
try {
ss = new ServerSocket(1234);
s = ss.accept();
dis = new DataInputStream(s.getInputStream());
dos = new DataOutputStream(s.getOutputStream());
while(!metin.equals("Exit")) {
metin = dis.readUTF();
Message_Area.setText("Server Diyor ki ; " + Writing_Area.getText().toString() + "\n" + metin);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/*
Sssifre = new ServerSocket(4321);
SocketSifre = Sssifre.accept();
disif = new ObjectInputStream(s.getInputStream());
dosif = new ObjectOutputStream(s.getOutputStream());
PrivateKey privateKey = (PrivateKey) disif.readObject();
JOptionPane.showMessageDialog(null,privateKey.toString()+ "gelen isim");
*/
}