private string FormatRequest(HttpRequest request)
        {
            var body = request.Body;

            //This line allows us to set the reader for the request back at the beginning of its stream.
            //request.EnableRewind();

            //We now need to read the request stream.  First, we create a new byte[] with the same length as the request stream...
            var     buffer        = new byte[Convert.ToInt32(request.ContentLength)];
            string  bodyMessage   = new StreamReader(request.Body).ReadToEnd();
            string  decodedString = AESEncryDecry.DecryptStringAES(bodyMessage);
            dynamic json          = JsonConvert.DeserializeObject(decodedString);

            request.ContentType = "application/json";
            //request.Body = decodedString;
            //...Then we copy the entire request stream into the new buffer.
            request.Body.ReadAsync(buffer, 0, buffer.Length);

            //We convert the byte[] into a string using UTF8 encoding...
            var bodyAsText = Encoding.UTF8.GetString(buffer);

            //..and finally, assign the read body back to the request body, which is allowed because of EnableRewind()
            request.Body = body;
            request.Body.Seek(0, SeekOrigin.Begin);
            return($"{request.Scheme} {request.Host}{request.Path} {request.QueryString} {bodyAsText}");
        }
Exemple #2
0
        public async Task <ActionResult <IEnumerable <TrackCabRecurso> > > ListarTodos([FromBody] Auth auth)
        {
            if (string.IsNullOrEmpty(auth.User) || string.IsNullOrEmpty(auth.Password))
            {
                return(BadRequest());
            }
            {
                var username = AESEncryDecry.DecryptStringAES(auth.User);
                var password = AESEncryDecry.DecryptStringAES(auth.Password);

                if (username == "keyError" && password == "keyError")
                {
                    return(Forbid("Credenciales incorrectas"));
                }
                else
                {
                    if (username == "Admin" && password == "YnterVS2020@669")
                    {
                        var trackCab = await _trackCabServicio.ListarTodosAsync();

                        var trackCabCRecurso = _mapper.Map <IEnumerable <TrackCab>, IEnumerable <TrackCabRecurso> >(trackCab);

                        return(Ok(trackCabCRecurso));
                    }
                    else
                    {
                        return(Forbid("Credenciales incorrectas"));
                    }
                }
            }
        }
Exemple #3
0
 static void Main(string[] args)
 {
     string json = "{profile: 'self', email: 'a @a.com', phone: '9748749692', password: '******'}";
     string encryptedStringFromAngular = "fXkLM7rOug4I0msVm6NVQ4Cz7RNdvwNApyXCE8JBvr5jWaEufrduA2d8MqzrJTWF4bUM9IMi53fBiQriOrHdYkioTY4NBjKF7SKO0rs19ZfH4cHi1jnD5ir3FrwVxPW4VYLTvzQYtSvGG4Vz5oNXbQ==";
     string decryptAES = AESEncryDecry.DecryptStringAES(encryptedStringFromAngular);
     //Crypto.Encrypt(json);//"U2FsdGVkX1 + HIU3e5wpRfW6H6B9AVueM0PZcqAeWzDpSzwDQsPQi5R7QIfu + owZI1ZJULi8MAIpS1IqOvwdAeg + Ytoq3ient6cysIEuhWISUU0lIPzRAv6QjcjBhAHuk";
     //string decryptAES = DecryptTest(encryptedAES);
     //GetBytes();
 }
Exemple #4
0
        public async Task <ActionResult <TrackCabRecurso> > BuscarPorSeguimiento(int pNroSeguimiento, System.DateTime pFechaHora, [FromBody] Auth auth)
        {
            if (string.IsNullOrEmpty(auth.User) || string.IsNullOrEmpty(auth.Password))
            {
                return(BadRequest());
            }
            else
            {
                var username = AESEncryDecry.DecryptStringAES(auth.User);
                var password = AESEncryDecry.DecryptStringAES(auth.Password);

                if (username == "keyError" && password == "keyError")
                {
                    return(Forbid("Credenciales incorrectas"));
                }
                else
                {
                    if (username == "Admin" && password == "YnterVS2020@669")
                    {
                        var trackCab = await _trackCabServicio.BuscarPorSeguimientoConLineas(pNroSeguimiento, pFechaHora);

                        var trackCabCRecurso = _mapper.Map <TrackCab, TrackCabRecurso>(trackCab);

                        if (trackCabCRecurso != null)
                        {
                            return(Ok(trackCabCRecurso));
                        }
                        else
                        {
                            return(NotFound("No se encontraron movimientos para el nro de seguimiento"));
                        }
                    }
                    else
                    {
                        return(Forbid("Credenciales incorrectas"));
                    }
                }
            }
        }
        public async Task Invoke(HttpContext context)
        {
            //First, get the incoming request
            if (context.Request.Method != "GET")
            {
                using (var bodyReader = new StreamReader(context.Request.Body))
                {
                    var          bodyAsText    = bodyReader.ReadToEnd();
                    string       decodedString = AESEncryDecry.DecryptStringAES(bodyAsText);
                    dynamic      json          = JsonConvert.DeserializeObject(decodedString);
                    var          obj           = JsonConvert.DeserializeObject <dynamic>(decodedString);
                    var          response      = JsonConvert.SerializeObject(obj);
                    MemoryStream mStrm         = new MemoryStream(Encoding.UTF8.GetBytes(response));
                    context.Request.Body        = mStrm;
                    context.Request.ContentType = "application/json";
                }

                //Copy a pointer to the original response body stream
                var originalBodyStream = context.Response.Body;

                //Create a new memory stream...
                using (var responseBody = new MemoryStream())
                {
                    //...and use that for the temporary response body
                    context.Response.Body = responseBody;

                    //Continue down the Middleware pipeline, eventually returning to this class
                    await _next(context);

                    //Format the response from the server
                    var response = await FormatResponse(context.Response);

                    //TODO: Save log to chosen datastore

                    //Copy the contents of the new memory stream (which contains the response) to the original stream, which is then returned to the client.
                    await responseBody.CopyToAsync(originalBodyStream);
                }
            }
            else
            {
                //Copy a pointer to the original response body stream
                var originalBodyStream = context.Response.Body;

                //Create a new memory stream...
                using (var responseBody = new MemoryStream())
                {
                    //...and use that for the temporary response body
                    context.Response.Body = responseBody;

                    //Continue down the Middleware pipeline, eventually returning to this class
                    await _next(context);

                    //Format the response from the server
                    var response = await FormatResponse(context.Response);

                    //TODO: Save log to chosen datastore

                    //Copy the contents of the new memory stream (which contains the response) to the original stream, which is then returned to the client.
                    await responseBody.CopyToAsync(originalBodyStream);
                }
            }
        }