我是NIO和Netty服务器客户端框架的新手,我有兴趣在NIOClientNew.java中加密我的数据(“Hello!”,如NIOClientNew.java类所示)并将其发送到Netty服务器并解密数据Netty处理程序类。
是否有人建议我如何处理NIO和Netty中的数据加密和解密?
'import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
public class NIOClientNew {
public static final String HELLO_REQUEST = "Hello!";
public static void main(String arg[]) {
SocketChannel sc = null;
try {
sc = SocketChannel.open();
sc.configureBlocking(false);
sc.connect(new InetSocketAddress(6565));
System.out.println("Sending a request to HelloServer");
while (!sc.finishConnect()) {
}
ByteBuffer buffer = ByteBuffer.allocate(65535);
buffer.putInt(HELLO_REQUEST.length());
buffer.put(HELLO_REQUEST.getBytes());
buffer.flip();
try {
sc.write(buffer);
} catch (IOException ex) {
System.out.println(ex.toString());
}
} catch (Exception e) {
System.out.println(e.toString());
} finally {
if (sc != null) {
try {
sc.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
'