两个凡是写了一段java代码, 大家来评价一下

宏哥 发布于 2018/04/25 14:37
阅读 531
收藏 0
    public static void main(String[] args) throws Exception {
        // parse arguments
        int port = args.length > 0 ? Integer.parseInt(args[0]) : 8080;

        // create server
        HTTPServer server = new HTTPServer(port);
        server.setExecutor(new ThreadPoolExecutor(
            8, Integer.MAX_VALUE, 300, TimeUnit.SECONDS, new SynchronousQueue<Runnable>()));
        VirtualHost host = server.getVirtualHost(null); // default virtual host

        // add plaintext test handler
        host.addContext("/hello", new ContextHandler() {
            @Override
            public int serve(Request req, Response resp) throws IOException {
                resp.getHeaders().add("Content-Type", "text/plain");
                resp.getHeaders().add("Content-Length", HELLO_LENGTH);
                resp.sendHeaders(200);
                resp.getOutputStream().write(HELLO_BYTES);
                return 0;
            }
        });

        host.addContext("/aes", new ContextHandler() {
            @Override
            public int serve(Request req, Response resp) throws IOException {
                resp.getHeaders().add("Content-Type", "text/plain");
                resp.sendHeaders(200);
                Map<String, String> params = req.getParams();
                String action = params.get("a");
                String key= params.get("k");
                String data = params.get("d");

                System.out.println(data);
                if(action.equals("e")){
                    System.out.println("Eecrypt");
                    String str = encrypt(data, key);
                    byte[]  encryptResult = str.getBytes();
                    System.out.println(str);

                    resp.getHeaders().add("Content-Length",Long.toString( encryptResult.length));
                    resp.getOutputStream().write(encryptResult);
                }else if(action.equals("d")){
                    System.out.println("Decrypt");

                    String str = decrypt(data, key);
                    byte[] decryptResult = str.getBytes();
                    System.out.println(str);
                    resp.getHeaders().add("Content-Length", Long.toString(decryptResult.length));
                    resp.getOutputStream().write(decryptResult);
                }else{
                    System.out.println("Other");
                    resp.getOutputStream().write(HELLO_BYTES);
                }
                return 0;
            }

 

加载中
0
张亦俊
张亦俊

线程池啊,我是不太喜欢这玩意

0
foy
foy

牛逼牛逼

0
乌龟壳
乌龟壳

php下aes加密你咨询下eechen,他以前提到过用openssl可以做

0
宏哥
宏哥

引用来自“乌龟壳”的评论

php下aes加密你咨询下eechen,他以前提到过用openssl可以做

我已经用java 做成 微服务给PHP调用了

openssl 都试过了, 算法不一样

0
沙罗曼蛇
沙罗曼蛇

菜鸡,各种硬编码,各种system.out.println。

返回顶部
顶部