// Path: jfxvnc-net/src/main/java/org/jfxvnc/net/rfb/codec/security/RfbSecurityEncoder.java
// public interface RfbSecurityEncoder extends ChannelOutboundHandler {
// 
// }
// 
// Path: jfxvnc-net/src/main/java/org/jfxvnc/net/rfb/exception/ProtocolException.java
// public class ProtocolException extends Exception {
// 
//   private static final long serialVersionUID = 5616560775184943955L;
// 
//   public ProtocolException(String message) {
//     super(message);
//   }
// 
//   public ProtocolException(String message, Throwable throwable) {
//     super(message, throwable);
//   }
// }


import java.nio.charset.StandardCharsets;
import java.security.spec.KeySpec;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import org.jfxvnc.net.rfb.codec.security.RfbSecurityEncoder;
import org.jfxvnc.net.rfb.exception.ProtocolException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
/*******************************************************************************
 * Copyright (c) 2016 comtel inc.
 *
 * Licensed under the Apache License, version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 *******************************************************************************/
package org.jfxvnc.net.rfb.codec.security.vncauth;





public class VncAuthEncoder extends MessageToByteEncoder<VncAuthSecurityMessage> implements RfbSecurityEncoder {

  private static Logger logger = LoggerFactory.getLogger(VncAuthEncoder.class);

  @Override
  protected void encode(ChannelHandlerContext ctx, VncAuthSecurityMessage msg, ByteBuf out) throws Exception {
    byte[] enc = encryptPassword(msg);
    logger.debug("VNC Auth encrypted: {}", enc);
    out.writeBytes(enc);
  }

// Path: jfxvnc-net/src/main/java/org/jfxvnc/net/rfb/codec/security/RfbSecurityEncoder.java
// public interface RfbSecurityEncoder extends ChannelOutboundHandler {
// 
// }
// 
// Path: jfxvnc-net/src/main/java/org/jfxvnc/net/rfb/exception/ProtocolException.java
// public class ProtocolException extends Exception {
// 
//   private static final long serialVersionUID = 5616560775184943955L;
// 
//   public ProtocolException(String message) {
//     super(message);
//   }
// 
//   public ProtocolException(String message, Throwable throwable) {
//     super(message, throwable);
//   }
// }


// Path: jfxvnc-net/src/main/java/org/jfxvnc/net/rfb/codec/security/vncauth/VncAuthEncoder.java
import java.nio.charset.StandardCharsets;
import java.security.spec.KeySpec;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import org.jfxvnc.net.rfb.codec.security.RfbSecurityEncoder;
import org.jfxvnc.net.rfb.exception.ProtocolException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/*******************************************************************************
 * Copyright (c) 2016 comtel inc.
 *
 * Licensed under the Apache License, version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 *******************************************************************************/
package org.jfxvnc.net.rfb.codec.security.vncauth;





public class VncAuthEncoder extends MessageToByteEncoder<VncAuthSecurityMessage> implements RfbSecurityEncoder {

  private static Logger logger = LoggerFactory.getLogger(VncAuthEncoder.class);

  @Override
  protected void encode(ChannelHandlerContext ctx, VncAuthSecurityMessage msg, ByteBuf out) throws Exception {
    byte[] enc = encryptPassword(msg);
    logger.debug("VNC Auth encrypted: {}", enc);
    out.writeBytes(enc);
  }

  private byte[] encryptPassword(VncAuthSecurityMessage msg) throws ProtocolException {