Exemple #1
0
        public static string PreparaQueryStringSegura(string[] keys, string[] vals)
        {
            NameValueCollection querystring = new NameValueCollection();

            for (int i = 0; i < keys.Length; i++)
            {
                querystring.Add(keys[i], vals[i]);
            }

            string encryptedString =
                CryptoQueryStringHandler.EncryptQueryStrings(querystring, WebConfigurationManager.AppSettings["CryptoKey"]);

            return(encryptedString);
        }
Exemple #2
0
        public static string[,] ProcessaQueryStringSegura(string querystring)
        {
            string sequencia = CryptoQueryStringHandler.DecryptQueryStrings(querystring, WebConfigurationManager.AppSettings["CryptoKey"]);

            string[] pares = sequencia.Split('&');

            string[,] retorno = new string[pares.Length, 2];

            for (int i = 0; i < pares.Length; i++)
            {
                retorno[i, 0] = pares[i].Split('=')[0];
                retorno[i, 1] = pares[i].Split('=')[1];
            }

            return(retorno);
        }
Exemple #3
0
        public static T ProcessaQueryStringSegura <T>(string secureuri, string key)
        {
            string sequencia = CryptoQueryStringHandler.DecryptQueryStrings(secureuri, WebConfigurationManager.AppSettings["CryptoKey"]);

            string[] pares = sequencia.Split('&');

            string[,] retorno = new string[pares.Length, 2];

            for (int i = 0; i < pares.Length; i++)
            {
                if (pares[i].Split('=')[0] == key)
                {
                    return(CTipos.CTipo <T>(pares[i].Split('=')[1]));
                }
            }

            return((T)typeof(T).GetField("MinValue").GetValue(null));
        }
Exemple #4
0
        /// <summary>
        /// Event that notify a module that new request is beginning.
        /// </summary>
        /// <param name="sender">Objeto que está realizando o evento.</param>
        /// <param name="e">Contém os dados do evento.</param>
        public void Application_BeginRequest(object sender, EventArgs e)
        {
            HttpContext context = HttpContext.Current;

            if (context.Request.Url.OriginalString.Contains("aspx") && context.Request.RawUrl.Contains("?"))
            {
                string queryStrings = context.Request.ServerVariables["QUERY_STRING"];

                if (!queryStrings.Equals(string.Empty))
                {
                    ////Checks whether the query string is encrypted
                    if (queryStrings.StartsWith(CryptoQueryStringHandler.ParameterName, StringComparison.OrdinalIgnoreCase))
                    {
                        if (context.Request.QueryString.AllKeys.Length == 1)
                        {
                            queryStrings = queryStrings.Substring(CryptoQueryStringHandler.ParameterName.Length);

                            string cryptoKey      = WebConfigurationManager.AppSettings["CryptoKey"];
                            string decryptedQuery = CryptoQueryStringHandler.DecryptQueryStrings(queryStrings, cryptoKey);

                            context.RewritePath(context.Request.AppRelativeCurrentExecutionFilePath, string.Empty, decryptedQuery);
                        }
                        else if (!queryStrings.Contains("AsyncFileUploadID"))
                        {
                            throw new Exception("Request inválido");
                        }
                    }
                    else if (context.Request.HttpMethod == "GET")
                    {
                        ////Encrypt the query string and redirects to the encrypted URL.
                        ////Remove if you don't want all query strings to be encrypted automatically.
                        string encryptedQuery = CryptoQueryStringHandler.EncryptQueryStrings(queryStrings, WebConfigurationManager.AppSettings["CryptoKey"]);
                        ////string encryptedQuery = Encrypt(query);
                        context.Response.Redirect(context.Request.AppRelativeCurrentExecutionFilePath + "?" + encryptedQuery);
                    }
                }
            }
        }