private static void SendServerHandshake(ServerHandshake handshake, Context context)
 {
     // generate a byte array representation of the handshake including the answer to the challenge
     string temp = handshake.ToString();
     byte[] handshakeBytes = Encoding.UTF8.GetBytes(temp);
     context.UserContext.Send(handshakeBytes, true);
 }
 private static ServerHandshake GenerateResponseHandshake(ClientHandshake handshake)
 {
     var responseHandshake = new ServerHandshake {Accept = GenerateAccept(handshake.Key)};
     return responseHandshake;
 }
        private void CheckAuthenticationResponse(Context context)
        {
            var receivedData = context.UserContext.DataFrame.ToString();
            var header = new Header(receivedData);
            var handshake = new ServerHandshake(header);

            if (Authentication.GenerateAccept(_handshake.Key) != handshake.Accept) return;

            ReadyState = ReadyStates.OPEN;
            IsAuthenticated = true;
            _connecting = false;
            context.UserContext.OnConnected();
        }