예제 #1
0
        protected override void Encode(IChannelHandlerContext context, byte[] message, IByteBuffer output)
        {
            if (message.Length % 16 != 0)
            {
                throw new InvalidOperationException($"Frame length should be a multiple of 16");
            }

            if (_logger.IsTrace)
            {
                _logger.Trace($"Sending frame (before encryption): {message.ToHexString()}");
            }
            _frameCipher.Encrypt(message, 0, 16, message, 0);
            _frameMacProcessor.AddMac(message, 0, 16, true);
            _frameCipher.Encrypt(message, 32, message.Length - 48, message, 32);
            _frameMacProcessor.AddMac(message, 32, message.Length - 48, false);
            if (_logger.IsTrace)
            {
                _logger.Trace($"Sending frame (after encryption):  {message.ToHexString()}");
            }
            output.WriteBytes(message);
        }
예제 #2
0
 private void WriteHeaderMac(IByteBuffer output)
 {
     _frameMacProcessor.AddMac(_encryptBuffer, 0, 16, _macBuffer, 0, true);
     output.WriteBytes(_macBuffer);
 }