Beispiel #1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var stringValue = reader.Value as string;

            if (string.IsNullOrEmpty(stringValue))
            {
                return(reader.Value);
            }

            var decryptedValue = StringEncryptor.Decrypt(stringValue, _passphrase);

            return(decryptedValue);
        }
Beispiel #2
0
    private static string ReadAndDecrypt(string name)
    {
        var path = PreparePath(name);

        if (File.Exists(path))
        {
            return(null);
        }

        var text = File.ReadAllText(path);

        return(StringEncryptor.Decrypt(text));
    }
        public void DecriptMethod_On_BTE_Return_ASD_WithKey_1()
        {
            // AAA
            // Arrange
            const string str             = "BTE";
            const string expected_result = "ASD";
            const int    key             = 1;

            // Act
            var actual_result = StringEncryptor.Decrypt(str, key);

            // Assert
            Assert.AreEqual(expected_result, actual_result);
        }
Beispiel #4
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Request.Params["_page"] == "_blank")
         return;
     string link = Request.Params["_link"];
     if (!(String.IsNullOrEmpty(link)))
     {
         StringEncryptor enc = new StringEncryptor();
         string[] permalink = enc.Decrypt(link.Split(',')[0]).Split('?');
         Page.ClientScript.RegisterStartupScript(GetType(), "Redirect", String.Format("location.replace(\'{0}?_link={1}\');\r\n", permalink[0], HttpUtility.UrlEncode(link)), true);
     }
     else
         Response.Redirect(ApplicationServices.HomePageUrl);
 }
Beispiel #5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string link = Request.Params["_link"];

        if (!(String.IsNullOrEmpty(link)))
        {
            StringEncryptor enc       = new StringEncryptor();
            string[]        permalink = enc.Decrypt(link.Split(',')[0]).Split('?');
            Page.ClientScript.RegisterStartupScript(GetType(), "Redirect", String.Format("location.replace(\'{0}?_link={1}\');\r\n", permalink[0], HttpUtility.UrlEncode(link)), true);
        }
        else
        {
            Response.Redirect("~/Pages/Home.aspx");
        }
    }
        //-------------------------------------------------------------------------------------------------
        //--- Create an Infoblock object out of an Encrypted String
        //-------------------------------------------------------------------------------------------------
        public static InfoBlock DecodeFromString(string aString)
        {
            InfoBlock myInfoBlock = null;

            theJsonSerializerSettings.TypeNameHandling = TypeNameHandling.None;

            try
            {
                string decryptedString = myStringEncryptor.Decrypt(aString);

                myInfoBlock = JsonConvert.DeserializeObject <InfoBlock>(decryptedString, theJsonSerializerSettings);
            }
            catch (Exception ex)
            {
            }
            return(myInfoBlock);
        }
Beispiel #7
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!(IsPostBack))
     {
         string link = Request.QueryString["l"];
         if (String.IsNullOrEmpty(link))
         {
             StringEncryptor se = new StringEncryptor();
             link = se.Decrypt(Request.QueryString["_link"]);
             link = HttpUtility.UrlDecode(link.Substring(2));
         }
         if (!(String.IsNullOrEmpty(link)))
         {
             if (!(link.Contains("&")))
             {
                 link = Encoding.Default.GetString(Convert.FromBase64String(link));
             }
             Match m = Regex.Match(link, "(.+?)(&|$)");
             if (m.Success)
             {
                 Div1.Visible         = true;
                 Extender1.Controller = m.Groups[1].Value;
                 m = m.NextMatch();
                 while (m.Success)
                 {
                     Match pair = Regex.Match(m.Groups[1].Value, "^(\\w+)=(.+)$");
                     if (pair.Success)
                     {
                         if (!(String.IsNullOrEmpty(Extender1.FilterFields)))
                         {
                             Extender1.FilterFields = (Extender1.FilterFields + ",");
                             ExtenderFilter.Value   = (ExtenderFilter.Value + ",");
                         }
                         Extender1.FilterFields = (Extender1.FilterFields + pair.Groups[1].Value);
                         ExtenderFilter.Value   = (ExtenderFilter.Value + pair.Groups[2].Value);
                     }
                     m = m.NextMatch();
                 }
             }
         }
     }
 }
    protected void processButton_Click(object sender, EventArgs e)
    {
        string stringToEncrypt = encryptBox.Text;
        string stringToDecrypt = decryptBox.Text;
        string encryptedString =
            StringEncryptor.Encrypt(stringToEncrypt);

        if (stringToDecrypt == "")
        {
            stringToDecrypt = encryptedString;
        }
        string decryptedString =
            StringEncryptor.Decrypt(stringToDecrypt);
        StringBuilder sb = new StringBuilder();

        sb.Append("Encrypted data: ");
        sb.Append(encryptedString);
        sb.Append("<br />Decrypted data: ");
        sb.Append(decryptedString);
        result.Text = sb.ToString();
    }
        protected virtual void ValidateUrlParameters()
        {
            bool success = true;

            foreach (string s in Request.QueryString.Keys)
            {
                if (Array.IndexOf(AllowedUrlParameters, s) == -1)
                {
                    success = false;
                    break;
                }
            }
            string link = Page.Request["_link"];

            if (!(String.IsNullOrEmpty(link)))
            {
                try
                {
                    StringEncryptor enc = new StringEncryptor();
                    link = enc.Decrypt(link.Replace(" ", "+").Split(',')[0]);
                    if (!(link.Contains('?')))
                    {
                        link = ('?' + link);
                    }
                    string[] permalink = link.Split('?');
                    ClientScript.RegisterClientScriptBlock(GetType(), "CommandLine", String.Format("var __dacl=\'{0}?{1}\';", permalink[0], BusinessRules.JavaScriptString(permalink[1])), true);
                }
                catch (Exception)
                {
                    success = false;
                }
            }
            if (!(success))
            {
                Response.StatusCode = 403;
                Response.End();
            }
            ClientScript.RegisterClientScriptBlock(GetType(), "ValidateUrlParameters", "var __dauh=1;", true);
        }
Beispiel #10
0
        protected override void OnInit(EventArgs e)
        {
            if (Request.Path.StartsWith((ResolveUrl(AquariumExtenderBase.DefaultServicePath) + "/"), StringComparison.CurrentCultureIgnoreCase))
            {
                ApplicationServices.HandleServiceRequest(Context);
            }
            if (Request.Params["_page"] == "_blank")
            {
                return;
            }
            string link = Request.Params["_link"];

            if (!(String.IsNullOrEmpty(link)))
            {
                StringEncryptor enc       = new StringEncryptor();
                string[]        permalink = enc.Decrypt(link.Split(',')[0]).Split('?');
                Page.ClientScript.RegisterStartupScript(GetType(), "Redirect", String.Format("window.location.replace(\'0?_link=1\');", permalink[0], HttpUtility.UrlEncode(link)), true);
                return;
            }
            else
            {
                string requestUrl = Request.RawUrl;
                if ((requestUrl.Length > 1) && requestUrl.EndsWith("/"))
                {
                    requestUrl = requestUrl.Substring(0, (requestUrl.Length - 1));
                }
                if (Request.ApplicationPath.Equals(requestUrl, StringComparison.CurrentCultureIgnoreCase))
                {
                    string homePageUrl = ApplicationServices.HomePageUrl;
                    if (!(Request.ApplicationPath.Equals(homePageUrl)))
                    {
                        Response.Redirect(homePageUrl);
                    }
                }
            }
            SortedDictionary <string, string> contentInfo = ApplicationServices.LoadContent();

            InitializeSiteMaster();
            string s = null;

            if (!(contentInfo.TryGetValue("PageTitle", out s)))
            {
                s = ApplicationServices.Current.Name;
            }
            this.Title = s;
            if (_pageTitleContent != null)
            {
                if (_isTouchUI)
                {
                    _pageTitleContent.Text = String.Empty;
                }
                else
                {
                    _pageTitleContent.Text = s;
                }
            }
            HtmlMeta appName = new HtmlMeta();

            appName.Name    = "application-name";
            appName.Content = ApplicationServices.Current.Name;
            Header.Controls.Add(appName);
            if (contentInfo.TryGetValue("Head", out s) && (_headContent != null))
            {
                _headContent.Text = s;
            }
            if (contentInfo.TryGetValue("PageContent", out s) && (_pageContent != null))
            {
                if (_isTouchUI)
                {
                    s = String.Format("<div id=\"PageContent\" style=\"display:none\">{0}</div>", s);
                }
                Match userControl = Regex.Match(s, "<div\\s+data-user-control\\s*=s*\"([\\s\\S]+?)\"\\s*>\\s*</div>");
                if (userControl.Success)
                {
                    int startPos = 0;
                    while (userControl.Success)
                    {
                        _pageContent.Controls.Add(new LiteralControl(s.Substring(startPos, (userControl.Index - startPos))));
                        startPos = (userControl.Index + userControl.Length);
                        string controlFileName  = userControl.Groups[1].Value;
                        string controlExtension = Path.GetExtension(controlFileName);
                        string siteControlText  = null;
                        if (!(controlFileName.StartsWith("~")))
                        {
                            controlFileName = (controlFileName + "~");
                        }
                        if (String.IsNullOrEmpty(controlExtension))
                        {
                            string testFileName = (controlFileName + ".ascx");
                            if (File.Exists(Server.MapPath(testFileName)))
                            {
                                controlFileName  = testFileName;
                                controlExtension = ".ascx";
                            }
                            else
                            {
                                if (ApplicationServices.IsSiteContentEnabled)
                                {
                                    string relativeControlPath = controlFileName.Substring(1);
                                    if (relativeControlPath.StartsWith("/"))
                                    {
                                        relativeControlPath = relativeControlPath.Substring(1);
                                    }
                                    siteControlText = ApplicationServices.Current.ReadSiteContentString(("sys/" + relativeControlPath));
                                }
                                if (siteControlText == null)
                                {
                                    testFileName = (controlFileName + ".html");
                                    if (File.Exists(Server.MapPath(testFileName)))
                                    {
                                        controlFileName  = testFileName;
                                        controlExtension = ".html";
                                    }
                                }
                            }
                        }
                        try
                        {
                            if (controlExtension == ".ascx")
                            {
                                _pageContent.Controls.Add(LoadControl(controlFileName));
                            }
                            else
                            {
                                string controlText = siteControlText;
                                if (controlText == null)
                                {
                                    controlText = File.ReadAllText(Server.MapPath(controlFileName));
                                }
                                Match bodyMatch = Regex.Match(controlText, "<body[\\s\\S]*?>([\\s\\S]+?)</body>");
                                if (bodyMatch.Success)
                                {
                                    controlText = bodyMatch.Groups[1].Value;
                                }
                                controlText = Localizer.Replace("Controls", Path.GetFileName(Server.MapPath(controlFileName)), controlText);
                                _pageContent.Controls.Add(new LiteralControl(controlText));
                            }
                        }
                        catch (Exception ex)
                        {
                            _pageContent.Controls.Add(new LiteralControl(String.Format("Error loading \'{0}\': {1}", controlFileName, ex.Message)));
                        }
                        userControl = userControl.NextMatch();
                    }
                    if (startPos < s.Length)
                    {
                        _pageContent.Controls.Add(new LiteralControl(s.Substring(startPos)));
                    }
                }
                else
                {
                    _pageContent.Text = s;
                }
            }
            else
            if (_isTouchUI)
            {
                _pageContent.Text = "<div id=\"PageContent\" style=\"display:none\"><div data-app-role=\"page\">404 Not Foun" +
                                    "d</div></div>";
                this.Title = "Task Manager";
            }
            else
            {
                _pageContent.Text = "404 Not Found";
            }
            if (_isTouchUI)
            {
                if (_pageFooterContent != null)
                {
                    _pageFooterContent.Text = "<footer style=\"display:none\"><small>&copy; 2017 Pergh. ^Copyright^All rights rese" +
                                              "rved.^Copyright^</small></footer>";
                }
            }
            else
            if (contentInfo.TryGetValue("About", out s))
            {
                if (_pageSideBarContent != null)
                {
                    _pageSideBarContent.Text = String.Format("<div class=\"TaskBox About\"><div class=\"Inner\"><div class=\"Header\">About</div><div" +
                                                             " class=\"Value\">{0}</div></div></div>", s);
                }
            }
            string bodyAttributes = null;

            if (contentInfo.TryGetValue("BodyAttributes", out bodyAttributes))
            {
                _bodyAttributes.Parse(bodyAttributes);
            }
            if (!(ApplicationServices.UserIsAuthorizedToAccessResource(HttpContext.Current.Request.Path, _bodyAttributes["data-authorize-roles"])))
            {
                string requestPath = Request.Path.Substring(1);
                if (!((WorkflowRegister.IsEnabled || WorkflowRegister.Allows(requestPath))))
                {
                    ApplicationServices.Current.RedirectToLoginPage();
                }
            }
            _bodyAttributes.Remove("data-authorize-roles");
            if (!(_isTouchUI))
            {
                string classAttr = _bodyAttributes["class"];
                if (String.IsNullOrEmpty(classAttr))
                {
                    classAttr = String.Empty;
                }
                if (!(classAttr.Contains("Wide")))
                {
                    classAttr = (classAttr + " Standard");
                }
                classAttr = ((classAttr + " ")
                             + (Regex.Replace(Request.Path.ToLower(), "\\W", "_").Substring(1) + "_html"));
                _bodyAttributes["class"] = classAttr.Trim();
            }
            _bodyTag.Text = String.Format("\r\n<body{0}>\r\n", _bodyAttributes.ToString());
            base.OnInit(e);
        }
Beispiel #11
0
 public RankingData JsonToSaveData(string _jsonData)
 {
     return(JsonUtility.FromJson <RankingData>(StringEncryptor.Decrypt(_jsonData)));
 }
Beispiel #12
0
 public string GetRawPassword()
 {
     return(EncryptPassword ? StringEncryptor.Decrypt(_password) : _password);
 }
Beispiel #13
0
 public SqlConnection getConnection()
 {
     return(new SqlConnection(StrCrypt.Decrypt(ConfigurationManager.ConnectionStrings["cashDesk"].ConnectionString)));
 }
Beispiel #14
0
 protected virtual void ValidateUrlParameters()
 {
     bool success = true;
     string link = Page.Request["_link"];
     if (!(String.IsNullOrEmpty(link)))
         try
         {
             StringEncryptor enc = new StringEncryptor();
             link = enc.Decrypt(link.Split(',')[0]);
             if (!(link.Contains('?')))
                 link = ('?' + link);
             string[] permalink = link.Split('?');
             ClientScript.RegisterClientScriptBlock(GetType(), "CommandLine", String.Format("var __dacl=\'{0}?{1}\';", permalink[0], BusinessRules.JavaScriptString(permalink[1])), true);
         }
         catch (Exception )
         {
             success = false;
         }
     if (!(success))
     {
         Response.StatusCode = 403;
         Response.End();
     }
 }