Search in sources :

Example 1 with Base64Encoder

use of io.netty.handler.codec.base64.Base64Encoder in project jgnash by ccavanaugh.

the class AttachmentTransferServer method startServer.

public boolean startServer(final char[] password) {
    boolean result = false;
    // If a password has been specified, create an EncryptionManager
    if (password != null && password.length > 0) {
        encryptionManager = new EncryptionManager(password);
    }
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(eventLoopGroup).channel(NioServerSocketChannel.class).option(ChannelOption.SO_KEEPALIVE, true).childHandler(new ChannelInitializer<SocketChannel>() {

            @Override
            public void initChannel(final SocketChannel ch) {
                ch.pipeline().addLast(new DelimiterBasedFrameDecoder(((TRANSFER_BUFFER_SIZE + 2) / 3) * 4 + PATH_MAX, true, Delimiters.lineDelimiter()), new StringEncoder(CharsetUtil.UTF_8), new StringDecoder(CharsetUtil.UTF_8), new Base64Encoder(), new Base64Decoder(), new ServerTransferHandler());
            }
        });
        // Start the server.
        final ChannelFuture future = b.bind(port).sync();
        if (future.isDone() && future.isSuccess()) {
            result = true;
            logger.info("File Transfer Server started successfully");
        } else {
            logger.info("Failed to start the File Transfer Server");
        }
    } catch (final InterruptedException e) {
        logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
        stopServer();
    }
    return result;
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) SocketChannel(io.netty.channel.socket.SocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) EncryptionManager(jgnash.util.EncryptionManager) DelimiterBasedFrameDecoder(io.netty.handler.codec.DelimiterBasedFrameDecoder) StringDecoder(io.netty.handler.codec.string.StringDecoder) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) Base64Encoder(io.netty.handler.codec.base64.Base64Encoder) StringEncoder(io.netty.handler.codec.string.StringEncoder) Base64Decoder(io.netty.handler.codec.base64.Base64Decoder)

Example 2 with Base64Encoder

use of io.netty.handler.codec.base64.Base64Encoder in project android2 by aqi00.

the class Des3Util method encrypt.

// 加密函数。key为密钥
public static String encrypt(String key, String raw) {
    byte[] enBytes = encryptMode(key, raw.getBytes());
    BASE64Encoder encoder = new BASE64Encoder();
    return encoder.encode(enBytes);
}
Also used : BASE64Encoder(com.example.test.encrypt.base64.BASE64Encoder)

Aggregations

BASE64Encoder (com.example.test.encrypt.base64.BASE64Encoder)1 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)1 ChannelFuture (io.netty.channel.ChannelFuture)1 SocketChannel (io.netty.channel.socket.SocketChannel)1 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)1 DelimiterBasedFrameDecoder (io.netty.handler.codec.DelimiterBasedFrameDecoder)1 Base64Decoder (io.netty.handler.codec.base64.Base64Decoder)1 Base64Encoder (io.netty.handler.codec.base64.Base64Encoder)1 StringDecoder (io.netty.handler.codec.string.StringDecoder)1 StringEncoder (io.netty.handler.codec.string.StringEncoder)1 EncryptionManager (jgnash.util.EncryptionManager)1