⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 client.java

📁 用JAVA开发的网络通信程序
💻 JAVA
字号:
import java.io.*;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import java.net.*;
public class client{
  public static void main(String args[])throws Exception{
   KeyGenerator kg=KeyGenerator.getInstance("DESede");      //获取密匙生成器
    kg.init(168);
    SecretKey k=kg.generateKey();                            //生成密匙
    FileOutputStream f_des=new FileOutputStream("c:/deskey.dat");
    ObjectOutputStream o=new ObjectOutputStream(f_des);
    o.writeObject(k);
    Cipher cp=Cipher.getInstance("DESede"); 
	  cp.init(Cipher.ENCRYPT_MODE,k);
	  FileInputStream fin=new FileInputStream("c:/temp.txt");
    FileOutputStream fout=new FileOutputStream("c:/desencryp.txt");
	  CipherOutputStream cout=new CipherOutputStream(fout,cp);
	  int b=0;
	  while((b=fin.read())!=-1){
	    cout.write(b);
	  }
	  cout.close();
	  fout.close();
	  fin.close();//生成密钥文件和对TEMP文件的加密文件(是好的)
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	File f1,f2=null;   //传输
	FileReader fin1,fin2=null;
	BufferedReader read1,read2 =null;
	int port =2345;
	Socket socket1=null;
	DataInputStream in1=null;
  DataOutputStream dout=null;
  String s1,s2=null;
  StringBuffer temp1=new StringBuffer();
  StringBuffer temp2=new StringBuffer();
	String content1,content2=null;
	try{
		socket1=new Socket("10.100.101.4",port);
	  in1=new DataInputStream(socket1.getInputStream());
		dout=new DataOutputStream(socket1.getOutputStream());
		}
	catch(IOException e){}
	if(socket1!=null){
	  f1=new File("c:/deskey.dat");
	  f2=new File("c:/desencryp.txt");
		fin1=new FileReader(f1);
		fin2=new FileReader(f2);
		read1=new BufferedReader(fin1);
		read2=new BufferedReader(fin2);
		while((s1=read1.readLine())!=null){
			temp1.append(s1);
			}
		  content1=new String(temp1);
		while((s2=read2.readLine())!=null){
			temp2.append(s2);
			}
		content2=new String(temp2);
	  try{
			dout.writeUTF("miyao:"+content1);
			dout.writeUTF("jiami:"+content2);
			}
		catch(IOException e){}
		}	
	try{socket1.close();}
	catch(IOException e){}	
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -