0

我是 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();
      }
        }
    }

}

}
'
4

0 回答 0