1 Star 0 Fork 0

cjy20175218/20175218cjy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
ClientThree.java 2.03 KB
一键复制 编辑 原始数据 按行查看 历史
cjy20175218 提交于 2019-05-27 21:38 . experiment5
import java.io.*;
import java.net.*;
import java.util.Scanner;
public class ClientThree {
public static void main(String args[]) throws Exception {
String key1="";
int n1=-1;
byte [] a1=new byte[128];
try{ File f=new File("key1.dat");
InputStream in = new FileInputStream(f);
while((n1=in.read(a1,0,100))!=-1) {
key1=key1+new String (a1,0,n1);
}
in.close();
}
catch(IOException e) {
System.out.println("File read Error"+e);
}
String sharekey="";
int n=-1;
byte [] a=new byte[128];
try{ File f=new File("Sharekey.dat");
InputStream in = new FileInputStream(f);
while((n=in.read(a,0,100))!=-1) {
sharekey=sharekey+new String (a,0,n);
}
in.close();
}
catch(IOException e) {
System.out.println("File read Error"+e);
}
Socket mysocket;
DataInputStream in=null;
DataOutputStream out=null;
System.out.println("请输入算式:");
Scanner scanner = new Scanner(System.in);
String str = scanner.nextLine();//输入算式
MyBC b=new MyBC();
str=b.result(str);
String secret=Encoder.AESEncode(key1, str);//客户端对表达式进行加密
String md=DigestPass.MD5(str);//客户端提供的MD5
key1 = Encoder.AESEncode(sharekey,key1);//客户端对密钥进行DH加密
try{ mysocket=new Socket("127.1.0.0",2010);
in=new DataInputStream(mysocket.getInputStream());
out=new DataOutputStream(mysocket.getOutputStream());
out.writeUTF(key1);
out.writeUTF(secret);
out.writeUTF(md);
String s=in.readUTF(); //in读取信息,堵塞状态
System.out.println("客户收到服务器的回答:"+s);
Thread.sleep(50000);
}
catch(Exception e) {
System.out.println("服务器已断开"+e);
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/cjy-123/20175218cjy.git
git@gitee.com:cjy-123/20175218cjy.git
cjy-123
20175218cjy
20175218cjy
master

搜索帮助

A270a887 8829481 3d7a4017 8829481