Commit aec6fd59 authored by 赵啸非's avatar 赵啸非

修改udp 加密解密

parent 59e3d409
......@@ -43,29 +43,37 @@ public class NettyUDPServerHandler extends SimpleChannelInboundHandler<DatagramP
byte[] bytes = new byte[byteBuf.readableBytes()];
byteBuf.readBytes(bytes);
String content = new String(bytes);
content = EncryptUtil.decrypt(content, ENCRYPT_STR);
ApiResp<String> resp = new ApiResp<>();
resp.setCode(YesNoEnum.YES.getValue());
log.info("receive->UDP entbefore:{}", packet.sender().toString() + "," + content);
try {
content = EncryptUtil.myEnscrt(content, 9, "FZV1D&tr", "w4*KbUamPdZDnDpG");
//EncryptUtil.decrypt(content, ENCRYPT_STR);
log.info("receive->UDPafter:{}", packet.sender().toString() + "," + content);
JSONObject jsonObject = JSON.parseObject(content);
log.info("receive->UDP:{}", packet.sender().toString() + "," + content);
String action = jsonObject.getString("action");
JSONObject jsonObject = JSON.parseObject(content);
resp.setMsg("获取服务端地址成功!");
if (!ObjectUtils.isEmpty(action) && "findserver".equals(action)) {
String URL = GlobalSysInfo.getParamValue(PARAM_SERVER_HTTP_URL, "http://192.168.0.98:11021");
resp.setData(URL);
} else {
resp.setCode(YesNoEnum.NO.getValue());
resp.setMsg("请求参数异常!");
}
String action = jsonObject.getString("action");
ApiResp<String> resp = new ApiResp<>();
resp.setCode(YesNoEnum.YES.getValue());
resp.setMsg("获取服务端地址成功!");
if (!ObjectUtils.isEmpty(action) && "findserver".equals(action)) {
String URL = GlobalSysInfo.getParamValue(PARAM_SERVER_HTTP_URL, "http://192.168.0.98:11021");
resp.setData(URL);
} else {
InetSocketAddress remoteAddress = new InetSocketAddress(packet.sender().getHostName(), CLIENT_PORT);
String sa = EncryptUtil.myReEnscrt(JSON.toJSONString(resp), 9, "FZV1D&tr", ENCRYPT_STR);
DatagramPacket sendpacket = new DatagramPacket(Unpooled.copiedBuffer(sa, CharsetUtil.UTF_8), remoteAddress);
//ctx.writeAndFlush(new DatagramPacket(Unpooled.copiedBuffer(JSON.toJSONString(resp), CharsetUtil.UTF_8), packet.sender()));
ctx.writeAndFlush(sendpacket);
} catch (Exception e) {
log.error("异常", e);
resp.setCode(YesNoEnum.NO.getValue());
resp.setMsg("请求参数异常!");
resp.setMsg("加密解密异常!");
}
InetSocketAddress remoteAddress = new InetSocketAddress(packet.sender().getHostName(), CLIENT_PORT);
DatagramPacket sendpacket = new DatagramPacket(Unpooled.copiedBuffer(EncryptUtil.encrypt(JSON.toJSONString(resp), ENCRYPT_STR), CharsetUtil.UTF_8), remoteAddress);
//ctx.writeAndFlush(new DatagramPacket(Unpooled.copiedBuffer(JSON.toJSONString(resp), CharsetUtil.UTF_8), packet.sender()));
ctx.writeAndFlush(sendpacket);
}
@Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment